我已经编写了一些代码来执行 httpGet,然后将 JSON 返回到主线程。有时虽然服务器已关闭,我想向主线程报告服务器已关闭但不知道如何使用处理程序正确执行此操作。
我的代码如下所示:
public class httpGet implements Runnable {
private final Handler replyTo;
private final String url;
public httpGet(Handler replyTo, String url, String path, String params) {
this.replyTo = replyTo;
this.url = url;
}
@Override
public void run() {
try {
// do http stuff //
} catch (ClientProtocolException e) {
Log.e("Uh oh", e);
//how can I report back with the handler about the
//error so I can update the UI
}
}
}