我需要显示progrees对话框。这很简单,但我绝对需要等待直到asynctask完成。这给我带来了一些困难。等待完成asynctask方法.get()
被使用。但是这个方法blocks
我的进度对话框。 那么,如何取消阻止progressdialog
获取或可以取代.get()
?disparying progressdialog的困难
我在以下方法调用操作:
Operation o = new Operation();
o.execute(params);
try {
o.get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
类操作
class Operation extends AsyncTask<String, Void, JSONObject> {
ProgressDialog pd;
Context con;
@Override
protected void onPreExecute() {
pd = new ProgressDialog(app);
pd.setOwnerActivity(app);
pd.setTitle("Идет загрузка...");
pd.setCancelable(true);
pd.show();
}
@Override
protected JSONObject doInBackground(String... option) {
/*
some job
*/
return json;
}
@Override
protected void onPostExecute(JSONObject result) {
super.onPostExecute(result);
pd.dismiss();
/*
some job
*/
}
}
在onPreExecute和隐藏在onPostExecute中显示的问题是什么? – stinepike
忘记删除评论。 .get()被调用时,preexecute/postexecute - dialog的问题不会弹出。在这种情况下,asynctask完成后对话框会闪烁半秒。 – Yarh
你可以调用doInBackground中的get方法 – stinepike