android - To check if user Is Logged in or not -


i using sharedpreferences check if user logged in or not. if user not logged in, taken login activity (or) info activity.

my code follows.

this in login activity.

sharedpreferences settings = getsharedpreferences(prefs_name, mode_private); sharedpreferences.editor editor = settings.edit(); editor.putboolean("logged", true); // set false when user logged out editor.commit(); // commit edits! 

i have checking code in main activity looks follows

sharedpreferences settings = getsharedpreferences(prefs_name, mode_private); boolean loggedin = settings.getboolean("logged", true); if (loggedin != true) {     // toast.maketext(this,"you logged in !!",3000).show();     /* intent = new intent(this,login.class);      startactivity(i);*/     intent intent = new     intent(mymainscreen.this, registered.class);     startactivity(intent); } else {     // toast.maketext(this,"you not logged in !!",3000).show();     intent intent = new     intent(mymainscreen.this, my_info.class);     startactivity(intent); } 

please me this, not able develop further without activity.

as understood, want check login state using sharedpreferences, default should think user logged out. so, when nothing in sharedpreferences, should take default value equals false not true.

sharedpreferences prefs = getsharedpreferences(pref_name, mode_private); intent intent = null; if (prefs.getboolean("logged_in", false)) { //user logged in before     intent = new intent(this, info.class); } else {     intent = new intent(this, registration.class); }  startactivity(intent); 

hope helps you!


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -