gpt4 book ai didi

java - 将登录状态存储在 sqlite 中或共享首选项

转载 作者:行者123 更新时间:2023-12-01 18:41:26 26 4
gpt4 key购买 nike

我制作应用程序,在我的应用程序中,我制作登录屏幕和注册屏幕,我想存储登录状态,如果用户登录应用程序,那么他永远不会再次登录,直到用户注销应用程序,但我也不知道在哪里共享偏好代码是实现的,请给我一个合适的解决方案这是我的完整登录屏幕代码截图

enter image description here

enter image description here

enter image description here

最佳答案

您可以使用共享首选项。它非常容易使用。

SharedPreferences userDetails =getSharedPreferences("userdetails", MODE_PRIVATE);
Editor edit = userDetails.edit();
edit.clear();
edit.putString("username", "");
edit.putString("password", "");
edit.commit();

您还可以通过以下方式获取数据:

userDetails.getString("username", "");

关于java - 将登录状态存储在 sqlite 中或共享首选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59925443/

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