Android switch between Login and MainActivity -
i have 2 activities. mainactivity
public class mainactivity extends sherlockfragmentactivity{ private sharedpreferences settings; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); settings = getpreferences(0); if (settings.getboolean("firststart", true)) { intent = new intent(getapplicationcontext(), loginactivity.class); startactivity(i); finish(); } } }
loginactivity called @ first time app starting. calls saveclass() method:
private void saveclass() { sharedpreferences preferences = getpreferences(0); sharedpreferences.editor editor = preferences.edit(); editor.putboolean("firststart", false); editor.commit(); toast.maketext(loginactivity.this, r.string.toast_login_success, toast.length_short).show(); intent = new intent(getapplicationcontext(), mainactivity.class); startactivity(i); finish(); }
and problem:
the loginactivity started. guess preferences not working fine. did make wrong or have code works?
instead of using getpreferences
try using
preferencemanager.getdefaultsharedpreferences(context);
Comments
Post a Comment