/**
* Created by HASEE.
*/
public class SPUtil {
private static SharedPreferences sp;
/**
* @param cxt 上下文
* @param key 读取具体内容关键字
* @param defValue 根据key读取不到内容时候的返回值结果
* @return 根据key取到结果
*/
public static boolean getBoolean(Context cxt,String key,boolean defValue){
if (sp == null){
sp = cxt.getSharedPreferences("config", Context.MODE_PRIVATE);
}
return sp.getBoolean(key,defValue);
}
/**
* @param cxt
* @param key
* @param value
* @return
*/
public static void saveBoolean(Context cxt,String key,boolean value){
if (sp == null){
sp = cxt.getSharedPreferences("config", Context.MODE_PRIVATE);
}
sp.edit().putBoolean(key,value).commit();
}
/**
* @param cxt 上下文
* @param key 存储数据关键字
* @param value 存储的json内容
*/
public static void saveString(Context cxt,String key,String value){
if (sp == null){
sp = cxt.getSharedPreferences("config", Context.MODE_PRIVATE);
}
sp.edit().putString(key,value).commit();
}
public static String getString(Context cxt,String key,String defValue){
if (sp == null){
sp = cxt.getSharedPreferences("config", Context.MODE_PRIVATE);
}
return sp.getString(key,defValue);
}
}