Fixes #1933428. Call onPrepareDialog() on managed dialogs after their onCreate() is finished.

This commit is contained in:
Romain Guy
2009-07-08 10:54:45 -07:00
parent 1bd3e0fb7e
commit 6de4aed1c6
2 changed files with 8 additions and 6 deletions

View File

@@ -857,7 +857,7 @@ public class Activity extends ContextThemeWrapper
if (dialogState != null) { if (dialogState != null) {
// Calling onRestoreInstanceState() below will invoke dispatchOnCreate // Calling onRestoreInstanceState() below will invoke dispatchOnCreate
// so tell createDialog() not to do it, otherwise we get an exception // so tell createDialog() not to do it, otherwise we get an exception
final Dialog dialog = createDialog(dialogId, false); final Dialog dialog = createDialog(dialogId, dialogState);
mManagedDialogs.put(dialogId, dialog); mManagedDialogs.put(dialogId, dialog);
onPrepareDialog(dialogId, dialog); onPrepareDialog(dialogId, dialog);
dialog.onRestoreInstanceState(dialogState); dialog.onRestoreInstanceState(dialogState);
@@ -865,13 +865,13 @@ public class Activity extends ContextThemeWrapper
} }
} }
private Dialog createDialog(Integer dialogId, boolean dispatchOnCreate) { private Dialog createDialog(Integer dialogId, Bundle state) {
final Dialog dialog = onCreateDialog(dialogId); final Dialog dialog = onCreateDialog(dialogId);
if (dialog == null) { if (dialog == null) {
throw new IllegalArgumentException("Activity#onCreateDialog did " throw new IllegalArgumentException("Activity#onCreateDialog did "
+ "not create a dialog for id " + dialogId); + "not create a dialog for id " + dialogId);
} }
if (dispatchOnCreate) dialog.dispatchOnCreate(null); dialog.dispatchOnCreate(state);
return dialog; return dialog;
} }
@@ -2407,7 +2407,7 @@ public class Activity extends ContextThemeWrapper
} }
Dialog dialog = mManagedDialogs.get(id); Dialog dialog = mManagedDialogs.get(id);
if (dialog == null) { if (dialog == null) {
dialog = createDialog(id, true); dialog = createDialog(id, null);
mManagedDialogs.put(id, dialog); mManagedDialogs.put(id, dialog);
} }

View File

@@ -292,9 +292,11 @@ public class Dialog implements DialogInterface, Window.Callback,
// internal method to make sure mcreated is set properly without requiring // internal method to make sure mcreated is set properly without requiring
// users to call through to super in onCreate // users to call through to super in onCreate
void dispatchOnCreate(Bundle savedInstanceState) { void dispatchOnCreate(Bundle savedInstanceState) {
if (!mCreated) {
onCreate(savedInstanceState); onCreate(savedInstanceState);
mCreated = true; mCreated = true;
} }
}
/** /**
* Similar to {@link Activity#onCreate}, you should initialized your dialog * Similar to {@link Activity#onCreate}, you should initialized your dialog