Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Dialog etc restore after rotation changed

How to restore the dialog etc after rotating the screen? For example, pop up an alertDialog to tell user some information. then the user rotate the screen to another orientation. How to restore the alertDialog? Can any one guide me to do it? Thanks!

Appended later:

I looked into the android source code and find these things:

Dialogs are stored in mManagedDialogs, and the related information is:

mManagedDialogs = new SparseArray<ManagedDialog>();

onSaveInstanceState related:

final void performSaveInstanceState(Bundle outState) {
    onSaveInstanceState(outState);
    saveManagedDialogs(outState);
}

In saveManagedDialogs, it has something to do with mManagedDialogs.

onRestoreInstanceState related:

final void performRestoreInstanceState(Bundle savedInstanceState) {
    onRestoreInstanceState(savedInstanceState);
    restoreManagedDialogs(savedInstanceState);
}

In restoreManagedDialogs, it has something to do with mManagedDialogs.

As you can see, for advanced feature, you must do the saving and restoring job by yourself. It may be a night mare when you have tons customized dialogs. I have not tried the complex dialog (has input EdiText, listView, say). In this way, I'd like to warn users: Never rotate the screen when inputing your info in the dialog... OR, lock the rotation dynamically when showing the dialog.

Thanks for all the people who answered me. Hope my information help you too.

like image 308
Henry Sou Avatar asked Sep 11 '10 02:09

Henry Sou


1 Answers

It is handled for you as long as you use Activity#showDialog to show it and Activity#onCreateDialog to create it: http://developer.android.com/reference/android/app/Activity.html#showDialog%28int%29

http://developer.android.com/reference/android/app/Activity.html#onCreateDialog%28int,%20android.os.Bundle%29

like image 186
Lance Nanek Avatar answered Nov 15 '22 10:11

Lance Nanek