Login and logout sessions android

非 Y 不嫁゛ 提交于 2020-01-05 04:45:30

问题


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.


回答1:


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();
    }


来源:https://stackoverflow.com/questions/13184261/login-and-logout-sessions-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!