我理解的SharedPreferences
来源:互联网 发布:上古卷轴5原始捏脸数据 编辑:程序博客网 时间:2024/06/15 15:20
android开发中,可能需要持久化少量的数据,譬如说一些用户设置的数据,用数据库就有点杀鸡用牛刀了,这时候可以尝试使用SharedPreferences。SharedPreferences是一种轻量级的存储数据的方式,使用xml文件来进行键值对方式的存储,而且使用起来非常轻量和快捷。
得到SharedPreferences:
<span style="font-family:SimSun;font-size:18px;">SharedPreferences sharedPreferences = getSharedPreferences( "usable_sharedPreferences", Context.MODE_PRIVATE);</span>
SharedPreferences使用一个内部类SharedPreferences.Editor来对数据进行编辑
得到edit:
<span style="font-family:SimSun;font-size:18px;">SharedPreferences.Editor editor = sharedPreferences.edit();</span>
提交数据:
<span style="font-family:SimSun;font-size:18px;">editor.putString(key, value);editor.commit();</span>
查询数据:
<span style="font-family:SimSun;font-size:18px;">String value = sharedPreferences.getString(key, "没有找到键:" + key + " 对应的值,请检查输入的键!");</span>
清空数据:
<span style="font-family:SimSun;font-size:18px;">editor.clear().commit();</span>
0 0
- 我理解的SharedPreferences
- Android中SharedPreferences的理解
- 我的SharedPreferences存取代码
- 我的android 第11天 - SharedPreferences
- 关于SharedPreferences共享参数的学习与理解
- 我理解我的忧郁
- 陈启申:我的理解
- 说说我的理解。
- 我理解的SOA
- 举案齐眉-----我的理解
- DLL我的理解
- 我理解的信息化
- 操作系统-我的理解
- 我理解的断言
- 汉诺塔 我的理解
- 我理解的RAID5
- 我的HTML 理解
- 我理解的ACID
- Unity3D研究院之Machine动画脚本自动生成AnimatorController(七十一)
- Win8.1和Centos 7双系统, 磁盘挂在问题,Unable to access “ *** Volume”
- linux下编译新内核,解决无法找到eth0设备问题,安装eth0网卡驱动
- geohash算法原理及实现方式
- 最长上升子序列nlogn算法
- 我理解的SharedPreferences
- MySQL中InnoDB和MyISAM两种表类型的区别
- vsftpd学习笔记二
- 关于未来规划
- LeetCode:Intersection of Two Linked Lists
- make的使用和Makefile的编写1
- C++中new与delete的用法
- 使用渐进式JPEG来提升用户体验
- GeoHash核心原理解析