android - How to retain a dialog's opened state onRestoreInstanceState -
say i've opened dialog , turn phone sideways. want dialog remain open. how acheive that?
here's i've tried
dialog dialog; boolean dialogshown = false; onclick: dialog = new dialog(login.this, r.style.no_title_dialog); dialog.show(); dialogshown = true; dialogbutton.onclick: //dostuff dialog.dismiss(); dialogshown = false; and
@override protected void onsaveinstancestate(bundle outstate) { super.onsaveinstancestate(outstate); if(dialogshown) { outstate.putboolean("dialogshown", true); } } @override protected void onrestoreinstancestate(bundle outstate) { super.onrestoreinstancestate(outstate); outstate.getboolean("dialogshown"); if(dialogshown){ dialog.show(); } } but when turn phone sideways, nullpointer exception on row:
dialog.show(); in onrestoreinstancestate, doesnt recognize dialog anymore?
you want have dialogshown = outstate.getboolean("dialogshown") key parameter getboolean() can string, it's not variable name.
stylistically, bundle should called instate in onrestoreinstancestate().
further, dialogfragments, 1 of problems they're supposed solve.
Comments
Post a Comment