You have to create your dialogs via the Activity's onCreateDialog event, as that is the point where they are managed by the Activity and they will be restored when the activity resumes.
Callback for creating dialogs that are managed (saved and restored) for you by the activity. If you use showDialog(int)
, the activity will call through to this method the first time, and hang onto it thereafter. Any dialog that is created by this method will automatically be saved and restored for you, including whether it is showing. If you would like the activity to manage the saving and restoring dialogs for you, you should override this method and handle any ids that are passed to showDialog(int). If you would like an opportunity to prepare your dialog before it is shown, override onPrepareDialog(int, Dialog)
.
Example usage:
public class MyClass extends Activity {
// ........ //
static final int DATE_DIALOG_ID = 1;
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth,
mDay);
}
return null;
}
public void launchSetDate() {
showDialog(DATE_DIALOG_ID);
}
}