【发布时间】:2016-06-21 08:29:47
【问题描述】:
我做了一些需要几秒钟的数据库保存。同时,我想显示我的 ProgressDialog 以表明该应用正在运行它。
class CreateNewSaves extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(activityContext);
pDialog.setMessage(activityContext.getString(R.string.upload_message));
pDialog.setIndeterminate(false);
pDialog.show();
pDialog.setCancelable(false);
pDialog.setCanceledOnTouchOutside(false);
}
/**
* Creating saves
* */
protected String doInBackground(String... args) {
//Some work done
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once done
pDialog.dismiss();
}
我不希望此 ProgressDialog 可取消,因此我愿意
setCancelable(false);
setCanceledOnTouchOutside(false);
但是当触摸屏幕或返回按钮时,ProgressDialog 仍然被取消。 我不确定它是隐藏还是关闭。
【问题讨论】: