Question

i'm making an app in android, it has more than one option in the menu, and the login information is needed to proceed in every option, so i want to make the user sign only once not each time he's choosing one of the options like the facebook application i have to sign in only once even when the application is running in the background it doesn't logout.. sry 4 the long explanation but i don't know even the keyword for searching about this issue..

can u please help me guys ? Thank u

Was it helpful?

Solution

Once the user enter the login credential first time then use SharedPreferences and set the value to isLogged to 1.

Next time when user open the app then check this variable if this variable value is '1' then open the home activity.

SharedPreferences sharedPref = getSharedPreferences("data",MODE_PRIVATE);
int number = sharedPref.getInt("isLogged", 0);
if(number == 0) {
    //Open the login activity and set this so that next it value is 1 then this conditin will be false.
    SharedPreferences.Editor prefEditor = sharedPref.edit();
    prefEditor.putInt("isLogged",1);
    prefEditor.commit();
} else {
       //Open this Home activity
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top