登录和注销会话android [英] Login and logout sessions android
问题描述
我是第一次开发android应用,我想进行登录和注销会话..我看到大多数人建议使用 SharedPreferences .但是,如何检查用户是否注销?如果用户未点击并单击我的应用程序,则登录页面将不会显示!用户可以立即转到主页.
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.
推荐答案
当用户登录成功时,调用setLogin函数并将boolean设置为true,然后当用户返回时,检查用户isLogin()是否返回true,然后使用Intent将用户重定向到主页.
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();
}
这篇关于登录和注销会话android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!