I create a ProgressDialog
in onCreateDialog()
like so:
protected Dialog onCreateDialog(int id) {
if (id == DIALOG_PROGRESS_ID)
{
ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage(getResources().getString(R.string.MyLabel));
dialog.setCancelable(false);
dialog.setIndeterminate(true);
return dialog;
}
}
Android, in its wisdom (or serious lack of it) decides to cache every dialog created through onCreateDialog(). Because of that, any subsequent call to showDialog(DIALOG_PROGRESS_ID)
results in the same ProgressDialog instance being used but the animation has stopped working.
I've tried to re-set indeterminate in onPrepareDialog()
, but that doesn't do anything. There is likewise no obvious method to call on the dialog instance that will reset the animation.
protected void onPrepareDialog(int id, Dialog dialog)
{
//This doesn't do anything
if (id == DIALOG_PROGRESS_ID)
((ProgressDialog)dialog).setIndeterminate(true);
super.onPrepareDialog(id, dialog);
}
EDIT: But maybe there is a way to get the ProgressBar itself and start it animating? so I tried the following after I asked this question:
@Override
protected void onPrepareDialog(int id, Dialog dialog)
{
if (id == DIALOG_PROGRESS_ID)
{
ProgressBar p = (ProgressBar) dialog.findViewById(android.R.id.progress);
if (p.getAnimation() != null)
p.startAnimation(p.getAnimation());
}
super.onPrepareDialog(id, dialog);
}
But it didn't work either!
So, does anyone know if there is a way to restart animation on a ProgressDialog? If not, is there a way that I can force every showDialog() call to call onCreateDialog()? (this second question was answered by @TuomasR, but after pondering it I don't think this is a very good solution to my problem)