android - Can not implement a save instance state for my switches -


edit:

okay, updated user "android developer" suggesting, , switches still remain unchecked every time enter app.

here snippet of code.. btw first app go easy. i'm learning.

public class mainactivity extends activity implements view.onclicklistener {    @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     preferencemanager.getdefaultsharedpreferences(this).getboolean("sw1",false); }  public void onclick(view v) {}  public void sw1(view view) {     // view checked?     boolean checked = ((switch) view).ischecked();     // check checkbox clicked     switch(view.getid()) {         case r.id.sw1:             if (checked) try {                 //toast.maketext(this, "sw1 checked", toast.length_short).show();                 runtime.getruntime().exec(new string[] { "su","-c","mod1" });                 preferencemanager .getdefaultsharedpreferences(this).edit().putboolean("sw1",true).commit();             } catch (ioexception e) {                 e.printstacktrace();             }             else try {                 //toast.maketext(this, "sw1 not checked", toast.length_short).show();                 runtime.getruntime().exec(new string[] { "su","-c","mod1b" });                 preferencemanager .getdefaultsharedpreferences(this).edit().putboolean("sw1",false).commit();             } catch (ioexception e) {                 e.printstacktrace();                 break;}     } } 

define "back out" of app.

if cause acitivity destoryed finishing it, shouldn't restore state , should store in real storage (sharepreferences, db, internal/external storage,...).

however, if wish restore after configuration has changed (for example after rotating device) , should restored automatically if use android's normal views, , if wish restore totally new customized views, restore them on oncreate() method , not on onrestoreinstancestate() method.

another alternative not finish activity, , show if close, using fragments instead of multiple activities.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -