Right now I am trying to create one Android application, assume it is going to be some “X” concept okay. So I am creating one login screen. What I want to do is at once if I logged in that application on my mobile, it should always be logged in whenever I try to access that application.
For example our Facebook, g-mail and yahoo etc.. in our mobile phones
What to do for that?
Use Shared Preference for auto login functionality. When users log in to your application, store the login status into sharedPreference and clear sharedPreference when users log out.
Check every time when the user enters into the application if user status from shared Preference is true then no need to log in again otherwise direct to the login page.
To achieve this first create a class, in this class you need to write all the function regarding the get and set value in the sharedpreference. Please look at this below Code.
Now in the main activity (The “Activity” where users will be redirected when logged in) first check
In Login activity if user login successful then set UserName using setUserName() function.