android SharedPreferences工具类
1、常规代码
SharedPreferences sp = getSharedPreferences("config",MODE_PRIVATE);
sp.edit().putBoolean("is_guide_showed",true).commit();
SharedPreferences sp = getSharedPreferences("config",MODE_PRIVATE);
boolean is = sp.getBoolean("is_guide_showed", false);
2、提取为工具类
/**
* @类名 PrefUtil
* @创建者 ppa
* @创建时间 2016-3-21
*
* @描述 SharedPreferences工具类
*/
public class PrefUtil {
public static final String PREF_NAME="config";
public static boolean getBoolean(Context cxt,String key,boolean value){
SharedPreferences sp=cxt.getSharedPreferences(PREF_NAME,Context.MODE_PRIVATE);
boolean is=sp.getBoolean(key,value);
return is;
}
public static void setBoolean(Context cxt,String key,Boolean value){
SharedPreferences sp=cxt.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
sp.edit().putBoolean(key, value).commit();
}
}