java - Permenantly storing a string, by a user? -


on main activity i'm looking variable, if variable contains string ("example string") go home-screen. if variable contains nothing ("") redirect them page can enter value via edittext , permanently store it. next time open app, have permanent string (until app deleted) , therefore go home-screen. research understand may have use shared preferences. have tried , think im not doing right. please illustrate code example of needs done code have posted.

mainactivity.class

//this class uses string, see if blank or contains string  public class mainactivity extends activity {       public static final string verified = ""; //originally comes blank           private edittext numberet; //edittext user enter string   //the string verified used in main activity determine xml file open. 

verified.class

// class used enter string , permanently store   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 verified;          string number;        bundle bundle = getintent().getextras();       verified = bundle.getstring("verified");      numberstring = bundle.getstring("numberstring")      verified = numberstring.tostring(); //set string verified permenantly       }        }); 

you may use , similar above answer saving string

sharedpreferences sharedpref = getsharedpreferences("app_name_prefs",                 context.mode_private); sharedpreferences.editor editor = sharedpref.edit(); editor.putstring("verified",  verified); editor.commit(); 

for getting string

sharedpreferences shared = getsharedpreferences("app_name_prefs",                 context.mode_private); string keyreturn = shared.getstring(key, ""); log.d("return value" , "verified " + verified); 

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? -