I create a ProgressDialog in onCreateDialog() like this:
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 absence), decides to cache every dialog created using onCreateDialog (). Because of this, any subsequent call to showDialog(DIALOG_PROGRESS_ID) causes the same instance of ProgressDialog to be used, but the animation has stopped working.
I tried to override the ambiguity in onPrepareDialog() , but that does nothing. There is also no obvious method of invoking an instance of a dialog that will reset the animation.
protected void onPrepareDialog(int id, Dialog dialog) {
EDIT: But maybe there is a way to get ProgressBar itself and start reviving it? 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 that didn't work either!
So, does anyone know if there is a way to restart the animation in ProgressDialog? If not, is there a way to force every call to showDialog () to call callCreateDialog ()? (@TuomasR answered this second question, but thinking about it, I don't think this is a very good solution to my problem)
android progressdialog
ageektrapped
source share