ProgressDialog不应取消

时间:2016-06-21 08:29:48

标签: android progressdialog

我做一些数据库保存需要几秒钟。在此期间,我想显示我的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仍然被取消。 我不确定它是隐藏还是被解雇。

1 个答案:

答案 0 :(得分:-1)

        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();