Android:为什么ProgressDialog有时会在onPause(onStop)上消失?

时间:2016-07-10 15:34:56

标签: android android-asynctask progressdialog

我在我的应用程序中运行AsyncTask以及ProgressDialog。当我离开应用程序时(暂停或停止时),当正在继续AsyncTask时,ProgressDialog会消失。尽管我在属性" setCancelable"中设置了false,但它仍然会发生。 ProgressDialog。但是当我返回app时,有时ProgressDialog仍然存在(就像我在这种情况下需要的那样)。我无法理解它的依赖性。这是AsyncTask中的代码:

class MyAsyncTask extends AsyncTask<JSONObject, Void, String> {


private Context mContext;
ProgressDialog mProgress;
private TaskComplete mCallback;

public MyAsyncTask(Context context){
    this.mContext = context;
    this.mCallback = (TaskComplete) context;

}

@Override
public void onPreExecute() {
    mProgress = new ProgressDialog(mContext);
    mProgress.setMessage("Please wait...It can take up to 3 minutes. Good luck:)");
    mProgress.show();
    mProgress.setCancelable(false);
    mProgress.setCanceledOnTouchOutside(false);
}


protected String doInBackground(JSONObject... objects) {
   //do some things
}


protected void onPostExecute(String result) {

    super.onPostExecute(result);
    mProgress.dismiss();
    mCallback.onTaskComplete(result);

}

0 个答案:

没有答案