【发布时间】:2014-10-05 21:05:01
【问题描述】:
在我的应用程序中,如果我在进度对话框之外单击或按下后退按钮,则进度对话框会在结束作业之前退出。如何避免这种行为?
代码如下:
private class DownloadDataFromServer extends AsyncTask<String, Integer, String> {
ProgressDialog dialog;
@Override
protected void onPreExecute() {
// Instantiate ProgressDialog and Set style to STYLE_HORIZONTAL
dialog = new ProgressDialog(HomePage.this);
dialog.setIndeterminate(false);
dialog.setMax(100);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setCancelable(true);
dialog.setTitle("Downloading");
dialog.setMessage("Please wait...");
dialog.show();
super.onPreExecute();
}
@Override
protected String doInBackground(String... urls) {
// My code
}
protected void onProgressUpdate(Integer... progress) {
// Update the progress
dialog.setProgress(progress[0]);
}
@Override
protected void onPostExecute(String result) {
// My code
dialog.dismiss();
}
【问题讨论】:
-
我不明白。
Do not allow users to cancel,但你明确设置了dialog.setCancelable(true);?您在使用该方法之前没有阅读该方法的文档吗? -
不,这是复制粘贴,我不介意。对不起
标签: android dialog block progressdialog back-button