I create a ProgressDialog
in onCreateDialog()
like so:
protected Dialog onCreateDialog(int id) {
if (id == DIALOG_PROGRESS_ID)
Ha! Got it... was also struggling with this. But calling:
removeDialog(DIALOG_PROGRESS_ID)
immediately after
dismissDialog(...)
removes it from the (presumed) dialog cache for the Activity and forces a call to onCreateDialog
. Create a new ProgressDialog in onCreateDialog
and the spinner animates everytime (for me at least).
Well, a not-so-cool workaround would to edit the parameters and not declaring the int private as in the examples. Of course, you lose the ability to switch on onCreateDialog, but you don't seem to be doing that anyway:
showDialog(++DIALOG_PROGRESS_ID);
Of course if the dialog is shown numerous times, you could have memory errors. Not pretty, but should work.
I don't like to removeDialog to recreate it on next showing. So, I resolve this issue by using onCreateDialog and onPrepareDialog:
1) In onCreateDialog I normally create the ProgressDialog. 2) In onPrepareDialog I reference the progressBar inside it and force to restart:
@Override
protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {
switch (id){
.....
case DIALOG_PROGRESS_ID:
ProgressBar p = (ProgressBar) dialog.findViewById(android.R.id.progress);
p.setVisibility(View.GONE);
p.setVisibility(View.VISIBLE);
break;
}
}
You can also try.
if (progressDialog != null) {
progressDialog.dismiss();
progressDialog = null;
}