android - Save Setting onDestroy -


how save setting after exit app using ondestroy?

example:

when app start, start main_activity.class

button button1;  public class main_activity extends activity {      super.oncreate(savedinstancestate);      ................ } 

added button named "button1" , give action open new activity when clicked

public void button1_newactivity (view v){      button1 = (button) findviewbyid(r.id.button1);      button1.setonclicklistener (new view.onclicklistener() {            public void onclick(view arg0) {                intent secondactivity=new intent (getapplicationcontext(), second_activity.class);                startactivity(secondactivity);           }      }); } 

added 2 checkbox on second_activity.class, default when app start checkbox1 selected , checkbox2 not selected. but, when checkbox2 selected , checbox1 automatically not selected, after pressed button start third_activity.class.

my question how can save setting, when exit app, start app again, automatically start third_activity.class not main_activity.class first one?

what should write in part

protected void ondestroy(){      .................... } 

use sharedpreferences store first activity. launch launcher activity before. in there check value saved in sharedpreference. if find have start 3rd activity oncreate of launcher start third , finish first one. example

public class main_activity extends activity {      super.oncreate(savedinstancestate);      sharedpreferences pref = getsharedpreferences(name);      boolean b = pref.getboolean("should_start_third", false);      if(b){         finish();         start third activity      }      ................ } 

here in sharedpreferences used should_start_third boolean value check if third activity start directly. default false.

you have save value of shared preferences after third checkbox selected. save use following.

getsharedpreferences(name).edit().putboolean("should_start_third", true).commit(); 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

How to call a javascript function after the page loads with a chrome extension? -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -