SharedPreferences史上最完整的使用步骤 5步走
2016-08-22 14:22
555 查看
欢迎一起讨论和学习,QQ:732258496 微信:15520726587
每日一言:高手不是叫所有人都输给你,而是叫所有人都想赢你!
一、初始化变量
public static SharedPreferences preferences;//当返回的时候保存在文件 private static final String ATTENDANCEREMIND = "attendance_remind";//文件名称二、设置xml文件名
preferences = getSharedPreferences(ATTENDANCEREMIND, MODE_PRIVATE);
三、获取xml中的值
boolean isAttendace = preferences.getBoolean("isAttend", true); String workOn=preferences.getString("workOn", "08:30");
四、把参数保存到xml文件当中
/** * 报存到attendance_remind.xml文件 * * @param preferences * @param isAttend 考情打卡提醒 * @param workOn 上班提醒时间 */ public static void saveAttendance(SharedPreferences preferences, Boolean isAttend, String workOn) { SharedPreferences.Editor editor; editor = preferences.edit(); editor.putBoolean("isAttend", isAttend);// 考情打卡提醒 editor.putString("workOn", workOn);// 上班提醒时间 editor.commit();// 提交 }
五、附件,xml文件的显示内容
xml文件 attendance_remind.xml
<?xml version='1.0' encoding='utf-8' standalone='yes'?>
<map>
<boolean name="isAttend" value="false"/>
<string name="workOn" >08:30</string>
</map>
相关文章推荐
- 使用Extjs完成对GridPanel的导出操作完整步骤
- Android JNI 使用的数据结构JNINativeMethod详解 ||建立Android SDK下的JNI、JAVA应用完整步骤---Android JAVA调用C++代码
- 完整linux下配置RMagick步骤 解决RMagick.so cannot open shared object问题
- php5.5使用PHPMailer-5.2发送邮件的完整步骤
- 虚拟打印机开发日志(一):使用x64 WIN7编译环境编译的完整步骤
- Linux 使用rpm方式安装最新mysql(5.7.17)完整步骤
- 使用UrlRewrite的完整步骤,页面静态化
- 使用Keytool工具生成证书及签名完整步骤
- 虚拟打印机开发日志(一):使用x64 WIN7编译环境编译的完整步骤
- 使用HTML 5和CSS3制作登录页面完整步骤
- SharedSDK(一):Android SharedSDK使用步骤
- linux 下面使用github完整步骤
- python使用jdango创建web项目完整步骤
- 使用Socket连接穿越CMWAP代理与完整的HTTP通信步骤7步
- 使用 HTML5 和 CSS3 制作登录页面完整步骤
- ngork完整使用步骤总结最新2017
- 一小时教程 MySQL从安装到使用 详细步骤 完整图文示例练习教程 学习笔记
- Linux系统下使用rpm方式安装最新mysql5.7.17完整步骤
- Windows Xp上手工创建数据库Oracle9i的完整步骤
- 使用正则表达式求完整路径中的文件名