android 经常用到的一些工具类--SharedPreferencesUtils
2017-03-28 16:49
567 查看
趁现在还没找到工作,把我经常要用的东西整理一下放到blog上,免得以后还要在项目里到处找
SharedPreferencesUtils工具类import android.content.Context;
import android.content.SharedPreferences;
/**
* author ${吴心良}
* data: 2017/2/16.
*/
public class SharedPreferencesUtils {
private static final String PRE_NAME = "config"; private static SharedPreferences sp; /** * 设置 boolean 值 * @param context * @param key * @param value */ public static void setBooleanValue(Context context, String key, boolean value){ if (sp == null) { sp = context.getSharedPreferences(PRE_NAME, Context.MODE_PRIVATE); } sp.edit().putBoolean(key, value).commit(); } /** * 返回 boolean 值 * @param context * @param key * @param defaultValue * @return */ public static boolean getBooleanValue(Context context, String key, boolean defaultValue){ if (sp == null) { sp = context.getSharedPreferences(PRE_NAME, Context.MODE_PRIVATE); } return sp.getBoolean(key, defaultValue); } /** * 设置 String 值 * @param context * @param key * @param */ public static void setStringValue(Context context, String key, String Value){ if (sp == null) { sp = context.getSharedPreferences(PRE_NAME, Context.MODE_PRIVATE); } sp.edit().putString(key, Value).commit(); } /** * 返回 String 值 * @param context * @param key * @param defaultValue * @return */ public static String getStringValue(Context context, String key, String defaultValue){ if (sp == null) { sp = context.getSharedPreferences(PRE_NAME, Context.MODE_PRIVATE); } return sp.getString(key, defaultValue); } /** * 设置Float值 * @param context * @param key * @param defaultValue */ public static void setFloatValue(Context context, String key, float defaultValue){ if (sp == null) { sp = context.getSharedPreferences(PRE_NAME, Context.MODE_PRIVATE); } sp.edit().putFloat(key, defaultValue).commit(); } /** * 返回Float值 * @param context * @param key * @param defaultValue * @return */ public static float getFloatValue(Context context, String key, float defaultValue){ if (sp == null) { sp = context.getSharedPreferences(PRE_NAME, Context.MODE_PRIVATE); } return sp.getFloat(key, defaultValue); }
}
相关文章推荐
- Android SharedPreferencesUtils数据保存工具类
- 关于Android轻量级存储SharedPreferencesUtils工具类
- Android中一些基本的工具类,如ToastUtils,PrefUtils,StreamUtils,MD5Utils...
- Android 简单存储 SharedPreferencesUtils
- Android常用工具类封装---SharedPreferencesUtil
- Android实战(橘子娱乐)-首页(第三篇 IRecyclerView自定义刷新头ClassicRefreshHeaderView和SharedPreferencesUtils)
- Android之SharedPreferencesUtils,支持对象,List
- Android常用工具类封装---SharedPreferencesUtil
- SharedPreferencesUtils 工具类 及 SharedPreferences apply和commit方法异同
- android开发中经常会用到的一些开源项目
- 开发j2ee时经常用到的工具和一些框架
- 经常用到经纬度数据,一些常用的经纬度经常记不住,索性一次性做个整理~~
- 做 ACM题时经常会用到排序 这里在网上找了一些要用到的qsort 的用法
- js验证表单(都是一些经常要用到的)
- servlet里经常会用到一些GET方法
- 一些经常会用到的Javascript检测函数
- 整理一些我经常用到的函数吧(不断更新)
- 经常用到的一些小病的预防的治疗
- 一些经常用到的web servers 服务
- 如何用上面的类求属性约简中经常要用到的一些东东