简体   繁体   English

登录和注销会话android

[英]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. 我是第一次开发一个android应用,我想进行登录和注销会话 I saw that most of the people suggested using SharedPreferences . 我看到大多数人建议使用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. 当用户登录成功时,调用setLogin函数并将boolean设置为true,然后当用户返回时,检查用户isLogin()是否返回true,然后使用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();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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