Android 使用SharePerference判断是否为第一次登陆的实现代码
作者:BrcLi 时间:2021-07-31 18:51:32
很多app中在第一次安装登陆时会有引导欢迎界面,第二次打开时就不再显示引导页面。
这个功能可以通过使用SharePreferences将用户的登陆信息保存起来,当app启动时判断登陆信息决定打开页面。
以下是创建的SharePreference类:
public class SharePreference {
Context context;
public SharePreference(Context context)
{
this.context = context;
}
/****设置状态 false为安装后第一次登录,true为已经登录过****/
public void setState()
{
SharedPreferences sp = context.getSharedPreferences("save.himi", Context.MODE_PRIVATE);
Editor editor = sp.edit();
editor.putBoolean("isLogin", true);
editor.commit();
}
/***获取状态***/
public boolean getState()
{
SharedPreferences sp = context.getSharedPreferences("save.himi", Context.MODE_PRIVATE);
boolean b = sp.getBoolean("isLogin", false);
return b;
}
}
在app打开前可以获取登陆状态,选择展示界面:
isLogin = sp.getState();
if(isLogin){
intent = new Intent(this,Activity1.class);
}
else {
sp.setState();<span style="white-space:pre"> </span>//将登陆状态设置为true;
intent = new Intent(this,Activity2.class);
}
以上所述是小编给大家介绍的Android 使用SharePerference判断是否为第一次登陆的实现代码网站的支持!
来源:http://blog.csdn.net/brcli/article/details/61195534
标签:android,shareperference,登陆
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
JavaWeb简单文件上传流程的实战记录
2023-04-02 09:14:59
![](https://img.aspxhome.com/file/2023/9/71889_0s.png)
Oracle + Mybatis实现批量插入、更新和删除示例代码
2022-01-18 16:05:58
Android Studio 透明状态栏的实现示例
2022-12-06 21:44:23
![](https://img.aspxhome.com/file/2023/8/137488_0s.png)
springboot使用hibernate validation对参数校验的实现方法
2023-01-06 22:34:16
maven profile自动切换环境参数的2种方法详解
2022-10-28 09:18:39
![](https://img.aspxhome.com/file/2023/6/64506_0s.png)
Java排序的那些事之sort方法的使用详解
2023-01-22 00:18:35
![](https://img.aspxhome.com/file/2023/4/61014_0s.png)
Android 实现悬浮窗功能
2021-09-17 20:02:07
![](https://img.aspxhome.com/file/2023/2/137832_0s.gif)
c# 成员类型访问权限低于字段本身的实现
2021-12-23 07:08:27
![](https://img.aspxhome.com/file/2023/9/78129_0s.png)
Java生成二维码可添加logo和文字功能
2021-06-23 22:24:35
java微信公众号开发(搭建本地测试环境)
2021-07-07 05:32:40
![](https://img.aspxhome.com/file/2023/6/63076_0s.png)
spring MVC实现简单登录功能
2023-11-13 05:20:48
![](https://img.aspxhome.com/file/2023/3/59563_0s.jpg)
浅谈SpringBoot资源初始化加载的几种方式
2022-03-09 08:14:34
![](https://img.aspxhome.com/file/2023/3/80253_0s.jpg)
C#用匿名方法定义委托的实现方法
2021-07-08 22:49:07
SpringBoot 使用 FTP 操作文件的过程(删除、上传、下载文件)
2021-07-26 10:40:05
Jenkins节点配置实现原理及过程解析
2023-02-14 11:53:30
![](https://img.aspxhome.com/file/2023/5/64045_0s.png)
处理java异步事件的阻塞和非阻塞方法分析
2023-04-16 05:06:01
![](https://img.aspxhome.com/file/2023/1/72341_0s.png)
java中的枚举类型详细介绍
2023-06-26 22:31:26
Android AIDL和远程Service调用示例代码
2022-07-14 03:06:15
![](https://img.aspxhome.com/file/2023/9/126799_0s.png)
C#中如何连接海康威视
2022-12-13 20:48:44
![](https://img.aspxhome.com/file/2023/9/102149_0s.png)
Android中实现EditText密码显示隐藏的方法
2022-04-13 22:33:56
![](https://img.aspxhome.com/file/2023/6/89506_0s.png)