我通过包含 AsyncTask 的外部类从服务器检索数据:
public class GetTask extends AsyncTask<String, Void, JSONObject> {
private Context context;
ProgressDialog dialog;
public GetTask(Context cxt) {
context = cxt;
dialog = new ProgressDialog(context);
}
protected void onPreExecute() {
dialog.setTitle("Load...");
dialog.setMessage("Data...");
dialog.show();
super.onPreExecute();
}
@Override
protected JSONObject doInBackground(String... url) {
// code for retreive data
return jArray;
}
protected void onPostExecute(JSONObject object) {
dialog.dismiss();
super.onPostExecute(object);
}
}
我从我的活动中调用此任务:
Tasks task = new Tasks();
JSONObject json = task.new GetTask(this).execute(ServerURL).get();
我的数据检索成功,但在 super.onPostExecute(object); 之后显示 ProgressDialog;方法,为什么?
PS对话框显示后:
// Make sure the identity of this thread is that of the local process,
// and keep track of what that identity token actually is.
Binder.clearCallingIdentity();
final long ident = Binder.clearCallingIdentity();
在内部 Looper.class
对不起,我的英语不好。))