【发布时间】:2012-10-27 16:25:22
【问题描述】:
我的应用程序在 AsyncTask 中的进度对话框出现问题:
我的AsyncTask 正在doInBackGround() 中从互联网上获取数据,我正在onPreExecute() 中开始进度对话框,在onPostExecute() 中完成对话框。
我在单击按钮时执行此 asyncTask。第一次单击此按钮(发生长时间操作)时,未显示进度对话框。但下次进度对话框会正常显示。
第一次运行AsyncTask,没有显示进度对话框可能是什么问题?
这是 onClick 方法:
public void onClickFind(View view){
new Task_Search().execute();
}
这是任务Task_Search:
private class Task_Search extends AsyncTask<Void, Void, Void> {
@SuppressWarnings("deprecation")
protected void onPreExecute() {
showDialog(DIALOG_TASKING);
}
protected Void doInBackground(Void... unused) {
//some geting of web content here
}
@SuppressWarnings("deprecation")
protected void onPostExecute(Void unused) {
dismissDialog(DIALOG_TASKING);
}
}
MainActivity中定义的进度对话框:
@SuppressWarnings("deprecation")
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_TASKING:
mSearchDialog = new ProgressDialog(this);
mSearchDialog.setMessage("Searching for field number..");
mSearchDialog.setCancelable(true);
return mSearchDialog;
}
return super.onCreateDialog(id);
}
在使用AsyncTask之前,我使用单独的线程来下载数据:在onClick中,我先启动progressDialog然后线程,当线程完成时progressDialog也停止了,
行为是相同的:
第一次点击按钮对话框没有显示,下次显示。
谁能帮忙?
【问题讨论】:
标签: android multithreading android-asynctask progressdialog