ProgressDialog 不应取消

ProgressDialog should not be cancelable

我做了一些需要几秒钟的数据库保存。同时,我想显示我的 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在触摸屏幕或返回按钮时仍然被取消。 我不确定它是被隐藏还是被忽略了。

        pDialog.show(); // this line should be at last. show will create your dialog, rest values will have no impact.

        pDialog.setCancelable(false);
        pDialog.setCanceledOnTouchOutside(false);

替换为

            pDialog.setCancelable(false);
            pDialog.setCanceledOnTouchOutside(false);     
            pDialog.show();