SharedPreferenceUtils
2016-04-26 15:31
344 查看
(转载)http://ztelovecly.cn/?p=153
package com.miaoqu.coffee_app.utils; import android.content.Context; import android.content.SharedPreferences; /** * SharedPreference工具类 * Created by Administrator on 2015/8/3. */ public class SharedPreferenceUtils { public final static String SETTING = "Setting"; public static void putValue(Context context, String key, int value) { SharedPreferences.Editor sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE).edit(); sp.putInt(key, value); sp.commit(); } public static void putValue(Context context, String key, boolean value) { SharedPreferences.Editor sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE).edit(); sp.putBoolean(key, value); sp.commit(); } public static void putValue(Context context, String key, String value) { SharedPreferences.Editor sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE).edit(); sp.putString(key, value); sp.commit(); } public static int getValue(Context context, String key, int defValue) { SharedPreferences sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE); int value = sp.getInt(key, defValue); return value; } public static boolean getValue(Context context, String key, boolean defValue) { SharedPreferences sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE); boolean value = sp.getBoolean(key, defValue); return value; } public static String getValue(Context context, String key, String defValue) { SharedPreferences sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE); String value = sp.getString(key, defValue); return value; } }
相关文章推荐
- (基础)html中使用javascript
- CSS3 Filter的十种特效
- js判断输入字符串是否为空、空格、null总结
- JavaScript与Java的关系(联系与区别)
- Node.js 基础命令
- js/javascript正则表达式中/g /i /m
- 【转】Js获取当前日期时间及其它操作
- js获取页面及个元素高度、宽度的代码
- JavaScript,入门使用
- 【应用】图片翻转js
- jQuery javascript获得网页的高度与宽度的实现代码
- javascript处理HTML的Encode(转码)和Decode(解码)总结
- JavaScript代码性能优化总结
- 《精通CSS:高级Web标准解决方案》学习过程--V
- [转]jQuery选择器总结
- JavaScript及C# URI编码详解
- javascript获取时间
- JavaScript及C# URI编码详解
- JavaScript及C# URI编码详解
- JavaScript及C# URI编码详解