Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dismissing Progress Dialog

I have a situation where I am loading a bunch of images. During this process, I am trying to show a progress Dialog until the images get loaded fully. I have overrided the onBackPressed() method, such that when the user presses the back button, the activity will be finished.

But if I press the back button when the progress dialog is being displayed, the back key event was not called. So I tried providing progressDialog.setCancelable(true). So this now allows me to dismiss the progress Dialog, but my back key event is not being called anyway and so my activity loads images in the background.

So how do I make both the progressDialog and activity to be stopped when the user presses the back key.

like image 902
Andro Selva Avatar asked Jun 06 '11 09:06

Andro Selva


2 Answers

Use Dialog.setOnCancelListener to cancel your background task

like image 80
Vincent Mimoun-Prat Avatar answered Oct 18 '22 14:10

Vincent Mimoun-Prat


Ok. I have found out a solution at last.

progressDialog.setCancelable(true);
    progressDialog.setOnCancelListener(new OnCancelListener() {

        public void onCancel(DialogInterface dialog) {

        Log.i("inside on cancel","Cancel Called");  
        finish(); //If you want to finish the activity.
        }
    });
like image 35
Andro Selva Avatar answered Oct 18 '22 14:10

Andro Selva