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.
Use Dialog.setOnCancelListener to cancel your background task