Android Dialog with dynamic text (API level < 8) killed on rotation -


i want create dialog string build @ runtime. looks api level 8 allows call showdialog bundle, have write app run on older oss.

how create dialog simple error string , make sure doesn't die when rotate screen.

i realize if override oncreatedialog, me. problem is, takes int constant. need pass string knows put in dialog.

if build dialog myself , call .show() on it, won't live through screen orientation change.

if you're targeting api level <8, it's sort of pain.

  1. set string message property on activity
  2. use onsaveinstancestate(bundle) , onrestoreinstancestate(bundle) manage property through configuration changes (such re-orientation)
  3. in onpreparedialog(int, dialog), set message of dialog property. if don't set in onpreparedialog, it'll re-display previous dialog (in case message needs change between dialogs.)

code:

@override protected void onsaveinstancestate(bundle outstate) {     super.onsaveinstancestate(outstate);      // save dialog message     if(dialogmessage != null) {         outstate.putstring(state_key_dialog_message, dialogmessage);     } }  @override protected void onrestoreinstancestate(bundle savedinstancestate) {     super.onrestoreinstancestate(savedinstancestate);      // load dialog message     if(savedinstancestate.containskey(state_key_dialog_message)) {         dialogmessage = savedinstancestate.getstring(state_key_dialog_message);     } }  /** oncreatedialog normal **/  @override protected void onpreparedialog(int id, dialog dialog) {     super.onpreparedialog(id, dialog);      switch(id) {     case dialog_message:          // decorate dialog appropriately         alertdialog messagedialog = (alertdialog) dialog;         messagedialog.setmessage(dialogmessage);     } } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -