android - Storing Values in SharedPreferences -
i trying store values username , password fields using sharedpreferences , use values populate edittext fields. fields not being populated , i'm not sure i'm doing wrong.
here login() method called when login button pressed. in set sharedpreferences values if login successful , check box checked.
public void login() { mloginprogress.setvisibility(view.visible); string usernamestring = memail.gettext().tostring(); string passwordstring = mpassword.gettext().tostring(); parseuser.logininbackground(usernamestring, passwordstring, new logincallback() { @override public void done(parseuser parseuser, parseexception e) { if (parseuser != null) { // login successful if (msavelogin.ischecked() == true) { sharedpreferences preferences = getsharedpreferences("login", mode_private); sharedpreferences.editor editor = preferences.edit(); editor.putstring("username", memail.gettext().tostring()); editor.putstring("password", mpassword.gettext().tostring()); } mloginprogress.setvisibility(view.gone); intent intent = new intent(loginactivity.this, mainactivity.class); loginactivity.this.startactivity(intent); } else { // login failed mloginprogress.setvisibility(view.gone); string exception = e.getmessage().tostring(); toast.maketext(getapplicationcontext(), exception, toast.length_short).show(); } } }); }
in oncreate() have code populate edittext fields sharedpreferences values.
sharedpreferences pref = getsharedpreferences("login", mode_private); memail.settext(pref.getstring("username", "")); mpassword.settext(pref.getstring("password", ""));
you forgot call editor.commit()
or editor.apply()
Comments
Post a Comment