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.
Android ProgressBar is a graphical view indicator that shows some progress. Android progress bar displays a bar representing the completing of the task. Progress bar in android is useful since it gives the user an idea of time to finish its task.
You can update the percentage of progress displayed by using the setProgress(int) method, or by calling incrementProgressBy(int) to increase the current progress completed by a specified amount. By default, the progress bar is full when the progress value reaches 100.
If you dismiss a Dialog
, you must not show the same instance again. Either create a new one, or use hide()
instead of dismiss()
. When using hide()
you still have to dismiss()
it when no longer needed.
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 next Activity.showDialog()
call. It will just call Activity.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 the ProgressDialog
's id instead of calling Dialog.dismiss()
. This will dismiss it and also remove that reference so when Activity.onShowDialog()
is called next it will use Activity.onCreateDialog()
instead of only Activity.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 call Activity.removeDialog()
. Otherwise it will only be dismissed. You could also call it right before you call Activity.showDialog()
.
Hope that helps someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With