Android Back Button and Progress Dialog

前端 未结 9 2304
攒了一身酷
攒了一身酷 2021-01-31 03:24

I have an AsyncTask that shows a progressDialog whilst working (it calls runOnUiThread from within doInBackground to show the progress dialog).

<
9条回答
  •  渐次进展
    2021-01-31 03:52

    javano... I tested your scenario using standard techniques, asyncTask and ProgressDialog. In my test, when the progressDialog is showing and i hit back, the progressdialog is dismissed and the background thread continues to run. I do not know why you need to call runOnUiThread.

    SO:

    show the progressDialog in onPreExecute place the long running task in doInBackground dismiss the progressDialog in onPostExecute pass the input parameters to your long running task as in:

    new MyAsynch().execute(password,inString);
    

    cancel() the asynchTask and progressDialog in onPause

    protected void onPause() {
        super.onPause();
        if (asynch != null) {asynch.cancel(true);}
        if (progress != null){progress.cancel();}
    }
    

    JAL

    I have some code here.

提交回复
热议问题