当前位置:网站首页>SharedPreferences数据储存
SharedPreferences数据储存
2022-07-23 11:26:00 【shuo277】
SharedPreferences
文件,类比.properties文件,数据存储都是使用键值对来存储
功能
写入和读取
可以将什么数据放入SharedPreferences?
原始基本数据,不可以复合型的数据
boolean float int long String
怎么获取到SharedPreferences?
SharedPreferences sp = getSharedPreferences(参数1,参数2) 参数1:存储文件名称 参数 MODE_PRIVATE 模式
写入的流程?
// 1 获取SharedPreferencesSharedPreferences sp=getSharedPreferences("loginfo",MODE_PRIVATE);// 2 借助EditorSharedPreferences.Editor edit = sp.edit();// 3 写入数据edit.putString("user",user); edit.putString("pwd",pwd);// 4 提交数据edit.commit();
读取的流程?
// 1 获取SharedPreferencesSharedPreferences sp=getSharedPreferences("loginfo",MODE_PRIVATE); // 2 根据key来获取值String user1 = sp.getString("user", ""); String pwd1 = sp.getString("pwd", "");
案例: 可以回填账号密码的登录功能
1.java文件

2.xml文件

边栏推荐
- aws篇6 aws iot
- STL deque
- VMware virtual machine download, installation and use tutorial
- Find the minimum value and location in multiple numbers (with repetition)
- AWS篇1
- [pyGame practice] playing poker? Win or lose? This card game makes me forget to eat and sleep.
- C language learning notes
- Part I basic information of the project
- 《快速掌握QML》第五章 组件
- C语言经典例题-商品检验码
猜你喜欢

超详细MP4格式分析

Six ways of uniapp route jump

centos7 中彻底卸载mysql

Deep understanding of L1 and L2 regularization

printf函数-转换说明

BGP federal experiment

xml-xxe漏洞之Fake XML cookbook

软件测试周刊(第81期):能够对抗消极的不是积极,而是专注;能够对抗焦虑的不是安慰,而是具体。

Ultra detailed MP4 format analysis
![[paper study] source mixing and separation robot audio steganography](/img/e1/55e8f6a3e754d728fe6b685a08fdbc.png)
[paper study] source mixing and separation robot audio steganography
随机推荐
种种迹象表明,Apple将有望支持AV1
超详细MP4格式分析
800V高压快充落地进程加快均胜电子获5亿欧元项目定点
Exclusive interview | open source Summer Star Niu Xuewei
奔驰新能源产品线:豪华新能源市场或将改变格局
【攻防世界WEB】难度三星9分入门题(下):shrine、lottery
C语言注释的方法
Guangzhou held a competition for quality and safety supervisors of agricultural products in the town and street
aws篇6 aws iot
Cookie和Session的区别
(BFS) template + example (maze, eight digits)
Fake XML cookbook of XML xxE vulnerability
Open source quadruped robot with design drawings and code "suggestions collection"
【Try to Hack】sql注入 Less7 (into outfile和布尔盲注)
[paper study] source mixing and separation robot audio steganography
3D数学 - 矢量
bug修改
老照片上色——DeOldify快速上手
任务切换的细节
可穿戴设备的自电容触摸控制器IT7259Q-13,IT7259EX-24