android - Prevent Dialog (or DialogFragment) from closing when app goes to background -


it's pretty common app show progress or alertdialog user. if user puts app background , returns later, want dialog still shown. there way make android handle this? i'd either not close dialog, or if reopen automatically when activity resumes.

so far it's looking no. haven't found ton of results (most people run issues orientation change, app not allow) few ask going background. have tried every permutation of dialogfragment , regular dialog, disappear when home button pressed , app opened task manager.

i don't have code show because it's in testing phase of various examples online. suspect have manage myself, checking in onresume() if should shown. if case can live it, i'd know sure.

first lets clear something, can see in next images, activity or fragment can destroyed many reasons, have deal want saving "the state of dialog".

activity life cycle enter image description here

now code:

public class customprogressdialog extends dialog {      private static final string showing_progress_dialog = "showing_progress_dialog";     private static final string string_progress_dialog = "string_progress_dialog";     private static final string showing_pop_up_dialog = "showing_pop_up_dialog";     private static final string string_pop_up_dialog = "string_pop_up_dialog";      public textview textview;      public customprogressdialog(context context) {         super(context, android.r.style.theme_translucent_notitlebar);          setcontentview(r.layout.progress_layout);          setcancelable(false);          textview = (textview) findviewbyid(r.id.progress_textview);     }  }   public class masteractivity extends fragmentactivity {     private customprogressdialog progressdialog;      @override     protected void oncreate(bundle savedinstancestate) {          super.oncreate(savedinstancestate);          setcontentview(r.layout.activity_master);          progressdialog = new customprogressdialog(this);          if (savedinstancestate != null) {             boolean showingdialog = savedinstancestate.getboolean(showing_progress_dialog);             if (showingdialog) {                 string msg = savedinstancestate.getstring(string_progress_dialog, getresources().getstring(r.string.progress_default_text));                 progressdialog.textview.settext(msg);                 progressdialog.show();             }              boolean mshowing_popupdialog = savedinstancestate.getboolean(showing_pop_up_dialog);             string temp_msg = savedinstancestate.getstring(string_pop_up_dialog, "");              if (mshowing_popupdialog)                 showpopupdialog(temp_msg);             }         }     }      @override     protected void onsaveinstancestate(bundle outstate) {         super.onsaveinstancestate(outstate);          if (progressdialog.isshowing()) {             outstate.putboolean(showing_progress_dialog, true);             outstate.putstring(string_progress_dialog, progressdialog.textview.gettext().tostring());         }          if (alert != null && alert.isshowing()) {             outstate.putboolean(showing_pop_up_dialog, true);             outstate.putstring(string_pop_up_dialog, mstring_dialog);         }     } } 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -