Shared Preferences Issue? Android Java -


hi have used shared preferences store string in 'verified'. on main activity need able string , used in if statement. on verified activity must able enter value edittext , store permenantly ( when app closed) until app deleted. here code doesnt save permenant string. think maybe onclicklistner? im not sure.

mainactivity

public class mainactivity extends activity {        public static final string verified = "";     @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);context.mode_private);  sharedpreferences settings = getsharedpreferences(verified, 0); string value = settings.getstring("key","");       if (mobileverified.equals("")){ 

...

verified class

public void oncreate(bundle savedinstancestate)       {         super.oncreate(savedinstancestate);         setcontentview(r.layout.verified);          button verifycompletebutton = (button) findviewbyid(r.id.verifycompletebutton);          verifycompletebutton.setonclicklistener(new view.onclicklistener()          {            public void onclick(view view)             {                   string numberstring;              string verified;               bundle bundle = getintent().getextras();               numberstring = bundle.getstring("numberstring");              verified = bundle.getstring("verified");                 //set string verified permenantly              sharedpreferences settings = getsharedpreferences(verified, 0);             sharedpreferences.editor editor = settings.edit();             editor.putstring("key", numberstring);             editor.commit();              }                });    } 

initialize sharedpreferences object inside oncreate() instead before oncreate() method below...

sharedpreferences settings;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     settings = preferencemanager.getdefaultsharedpreferences(this);    string value = settings.getstring("key",""); } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -