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
Post a Comment