gpt4 book ai didi

Android:防止用户在登录后返回登录页面

转载 作者:行者123 更新时间:2023-11-29 18:22:36 25 4
gpt4 key购买 nike

我的 android 应用程序中有一个登录页面。我想阻止用户在登录后返回登录页面。另外,当用户重新打开应用程序时,如果他之前登录过,我想直接进入主页面,而不必进入登录页面。

最好的方法是什么?我想到的一个想法是将登录参数保存在一个cookie中,然后,当应用程序重新打开时,如果cookie包含一些登录信息,我会膨胀主页,否则,我会膨胀登录页面。这是最好的方法吗?

谢谢,

最佳答案

1) 在显示登录对话框/Activity 之前,只需检查您的偏好是否存在特殊标志:

Context context=this.getApplicationContext();
SharedPreferences settings=context.getSharedPreferences(PREFERENCES, 0);
boolean isLogged=settings.getBoolean("isLogged", false);

根据 isLogged 值,您可以重定向到登录页面或其他页面

2) 登录后在登录页面的某处保存 isLogged 状态,例如:

Context context=this.getApplicationContext();
SharedPreferences settings=context.getSharedPreferences(PREFERENCES, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("isLogged", true);
editor.commit();

这就是所有人!

关于Android:防止用户在登录后返回登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4544302/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com