SharedPreferencesUtil
2017-07-12 14:56
316 查看
/** *配置存储 */ public class SharedPreferencesUtil { private final static String NAME = "settings"; /** * put int value * @param context * @param key * @param value */ public static void putIntValue(Context context,String key,int value){ SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE); Editor edit = sharedPreferences.edit(); edit.putInt(key, value); edit.commit(); } /** * put float value * @param context * @param key * @param value */ public static void putFloatValue(Context context,String key,float value){ SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE); Editor edit = sharedPreferences.edit(); edit.putFloat(key, value); edit.commit(); } /** * put boolean value * @param context * @param key * @param value */ public static void putBooleanValue(Context context,String key,boolean value){ SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE); Editor edit = sharedPreferences.edit(); edit.putBoolean(key, value); edit.commit(); } /** * put long value * @param context * @param key * @param value */ public static void putLongValue(Context context,String key,long value){ SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE); Editor edit = sharedPreferences.edit(); edit.putLong(key, value); edit.commit(); } /** * put String value * @param context * @param key * @param value */ public static void setStringValue(Context context,String key,String value){ SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE); Editor edit = sharedPreferences.edit(); edit.putString(key, value); edit.commit(); } public static int getIntValue(Context context,String key,int defValue){ SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE); return sharedPreferences.getInt(key, defValue); } public static float getFloatValue(Context context,String key,float defValue){ SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE); return sharedPreferences.getFloat(key, defValue); } public static long getLongValue(Context context,String key,long defValue){ SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE); return sharedPreferences.getLong(key, defValue); } public static String getStringValue(Context context,String key,String defValue){ SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE); return sharedPreferences.getString(key, defValue); } public static boolean getBooleanValue(Context context,String key,boolean defValue){ SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE); return sharedPreferences.getBoolean(key, defValue); } }
相关文章推荐
- SharedPreferencesUtil
- SharedPreferencesUtil
- Android常用工具类封装---SharedPreferencesUtil
- SharedPreferencesUtil与ASimpleCache
- Android常用工具类封装---SharedPreferencesUtil
- SharedPreferencesUtil
- SharedPreferencesUtil 工具类的作用
- SharedPreferencesUtil &Version检测 &Gson工具类
- SharedPreferencesUtil sharedPreferences工具类
- getSharedPreferences两个参数的意义
- getSharedPreferences()与getSharedPreferences()与getDefaultSharedPreferences()的区别
- SharedPreferenceUtil
- android apk反编译安全检查----shared_preferences任意读写漏洞
- getPreferences,getSharedPreferences,getDefaultSharedPreferences的区别
- android.content.SharedPreferences.edit()
- 12.数据储存1:SharedPreferences…
- how to use shared Preferences
- getSharedPreferences只能继承Activity才能使用
- Android——SharedPreferences