android 中共享变量SharedPreferences的使用
来源:互联网 发布:关闭windows数字签名 编辑:程序博客网 时间:2024/05/30 21:59
SharedPreferences 的使用具体请参考API:
Interface for accessing and modifying preference data returned by getSharedPreferences(String, int). For any particular set of preferences, there is a single instance of this class that all clients share. Modifications to the preferences must go through an SharedPreferences.Editor object to ensure the preference values remain in a consistent state and control when they are committed to storage. Objects that are returned from the various get methods must be treated as immutable by the application.
Note: currently this class does not support use across multiple processes. This will be added later.
使用如下:
public boolean saveData(String userName,String password) { boolean flag = false;// 1.获取共享参数 SharedPreferences sharedPreferences = context.getSharedPreferences("qjg", context.MODE_WORLD_READABLE+context.MODE_WORLD_WRITEABLE);// 2.通过共享参数获取编辑器对象 Editor editor = sharedPreferences.edit();// 3.通过编辑器对象放入相应的值 editor.putString("name",userName); editor.putString("password",password);// 4.提交数据 ,必须使用。否则,写不到文件中! flag = editor.commit(); return flag; }
0 0
- android 中共享变量SharedPreferences的使用
- Android中SharedPreferences共享参数的封装
- Android中的共享参数--SharedPreferences的使用
- android 中 SharedPreferences 的使用!
- Android中SharedPreferences的使用
- android中SharedPreferences的使用
- Android中SharedPreferences的使用
- Android中SharedPreferences的使用
- android中SharedPreferences的使用
- Android中SharedPreferences的使用
- Android中SharedPreferences的使用
- [Android]Android中Application、静态变量和Sharedpreferences的使用与区别
- Android中Application、静态变量和Sharedpreferences的使用与区别
- 学习Android中Application、静态变量和Sharedpreferences的使用与区别
- 学习Android中Application、静态变量和Sharedpreferences的使用与区别
- android中SharedPreferences使用
- Android中SharedPreferences的使用详解
- Android中关于SharedPreferences的使用简介
- 黑马程序员 第三篇 Java 集合框架 (Foundation; completed)
- Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解
- hdu4003
- VS2013加上注释的快捷键,以及批量注释的快捷键
- 数据库方面的知识
- android 中共享变量SharedPreferences的使用
- Mysql导出逗号分隔的csv文件
- 勿忘初心,不断进步
- 关于Unity3d发布后Scene场景的设置(代码控制)
- trace walk DEMO
- Ubantu(Linux)下安装Eclipse并配置 PyDev
- HDU3090 Go Home
- Zend Studio 安装+破解
- 字符和字符串