This seems to be an Android-wide problem, which you can see in API demos under Views -> Progress Bar -> Dialogs.
Basically, if you show a progress dialog, it works as expected the first time around. If you dismiss it and show it again (without destroying the activity or anything like that), the spinning image stops spinning. In the API Demo you can see this by clicking "Show Indeterminate", pressing back to dismiss the dialog, and clicking the button again.
I've tried constructing my own progress dialog, however it shows the same problem, as the problem is with the "ProgressBar" spinning image.
I am wondering if anyone has a workaround for this problem.
You don't have to use
onCreateDialog
forProgressDialog
objects, as explained here http://developer.android.com/guide/topics/ui/dialogs.html#ProgressDialog . You should create and show the progress dialog in the main code instead of usingshowDialog
andonCreateDialog
.You can define class and implement the AsyncTask.There you define your background processes in the doinbackground() method like this.
You can also show your progress information by the onProgressUpdate() method.Check a full easy to follow tutorial at http://www.androidcookers.co.cc/2011/12/want-to-run-progress-dialog-in-android.html
If you dismiss a
Dialog
, you must not show the same instance again. Either create a new one, or usehide()
instead ofdismiss()
. When usinghide()
you still have todismiss()
it when no longer needed.You can declare a
ProgressDialog
instance in your Activity and overrideonCreateDialog(int)
. Then instead of making a call toshowDialog(int)
you just assign your instance ofProgressDialog
the call toonCreateDialog(int)
where you will calldialog.show()
.I was looking for the same answer, however none of the answers here worked for me because I wanted to use the Activity's dialog methods like
Activity.showDialog()
so I didn't have to manage them myself and also so they would automatically be recreated on a rotation.Like some of the other answers said, if dismiss() is called on a
ProgressDialog
it will stop spinning.Activity.onCreateDialog()
saves a reference to the dialog, so once it is created it will not be recreated on the nextActivity.showDialog()
call. It will just callActivity.onPrepareDialog()
and use the instance it already had. If it was dismissed then it won't spin when it is showed again.You can force it to recreate itself if you call
Activity.removeDialog()
with theProgressDialog
's id instead of callingDialog.dismiss()
. This will dismiss it and also remove that reference so whenActivity.onShowDialog()
is called next it will useActivity.onCreateDialog()
instead of onlyActivity.onPrepareDialog()
and create a brand new (and spinning) instance.Make sure if you have a
ProgressDialog
that can be dismissed or canceled you set a listener so you can callActivity.removeDialog()
. Otherwise it will only be dismissed. You could also call it right before you callActivity.showDialog()
.Hope that helps someone.