简体   繁体   中英

Login and logout sessions android

I am developing an android app for the first time and I wanted to make the sessions for login and logout. I saw that most of the people suggested using SharedPreferences . But how can I check if the user logged out? If the user does not and clicks on my app, then the sign in page won't show up! The user can immediately go to the main page.

When the user login successfully call the setLogin function and set boolean as true and when the user come back then check the whether user isLogin() if it return true then redirect user to main page with Intent.

public boolean isLogin() {

        return pref.getBoolean("login", false);

    }

    public void setLogin(Boolean x) {
        SharedPreferences.Editor editor = pref.edit();
        editor.putBoolean("login", x);
        editor.commit();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM