Question

I have an AsyncTask in this form

private class AsyncOperation extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute(){
            pDialog = new ProgressDialog(MyActivity.this);
            pDialog.setMessage("Waiting...");
            pDialog.show();
        }
        @Override
        protected Void doInBackground(Void... params) {
           ...
          return null
         }

        protected void onPostExecute(Void params){
            pDialog.dismiss();


        }

If the user touch the screen the waiting dialog is closed before the end of the task, if the screen goes in standby during the operation, if I return to the app and the task isn't finished, same issue.

How could I fix this issue? Also any suggestion to improve the way I perform async operation that requires times on holo App will be appreciated.

Was it helpful?

Solution

You have to set the cancellable property of your ProgresDialog to false:

protected void onPreExecute(){
        pDialog = new ProgressDialog(MyActivity.this);
        pDialog.setMessage("Waiting...");
        pDialog.setCancelable(false);
        pDialog.show();
}    

This makes sure that the progressDialog does'nt disappear when u click anywhere else other than the dialog.

OTHER TIPS

you can set the cancellable property by using this.

Dialog dialog;

@Override

    protected void onPreExecute(){
        super.onPreExecute();

        dialog = ProgressDialog.show(Login.this,"Connecting...", "Please wait...", false,true);

    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top