Android Java sharedPreferences
logic issue
I have an app that has a sign in and sign out in it.
I want, when the user first downloads the app, it is sign out. Then when he signs in using the button, a sharedPreference
value saves. Now next time he opens the app, it will automatically sign him in. Lets say he signs out then closes the app, so now when he opens it, it will sign him out. Thats how it goes like most apps.
What I did, at the first of the activity I added this
SharedPreferences SiggnedIn = getSharedPreferences("YesOrNo", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = SiggnedIn.edit();
editor.putBoolean("SiggnedIn?", false);
editor.commit();
then when the user clicks the button to signs out
SharedPreferences SiggnedIn = getSharedPreferences("YesOrNo", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = SiggnedIn.edit();
editor.putBoolean("SiggnedIn?", false);
editor.commit();
and if he clicks it to sign in
SharedPreferences SiggnedIn = getSharedPreferences("YesOrNo", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = SiggnedIn.edit();
editor.putBoolean("SiggnedIn?", true);
editor.commit();
and at last, if I have a method that updates everything every second.
so in it, I add
SharedPreferences SiggnedIn = getSharedPreferences("YesOrNo", Activity.MODE_PRIVATE);
boolean myIntValue = SiggnedIn.getBoolean("SiggnedIn?", false);
if(myIntValue){
SignHimIn();
}
That doesn't work.