今天需要用到SharePreference来保存一些设置参数,因为要用到很多次 所以对它进行了封装:

public class PrefUtils {

    public static void putBoolean(String key, boolean value, Context ctx) {
SharedPreferences sp = ctx.getSharedPreferences("config",
Context.MODE_PRIVATE);
sp.edit().putBoolean(key, value).commit();
} public static boolean getBoolean(String key, boolean defValue, Context ctx) {
SharedPreferences sp = ctx.getSharedPreferences("config",
Context.MODE_PRIVATE);
return sp.getBoolean(key, defValue);
} public static void putString(String key, String value, Context ctx) {
SharedPreferences sp = ctx.getSharedPreferences("config",
Context.MODE_PRIVATE);
sp.edit().putString(key, value).commit();
} public static String getString(String key, String defValue, Context ctx) {
SharedPreferences sp = ctx.getSharedPreferences("config",
Context.MODE_PRIVATE);
return sp.getString(key, defValue);
} public static void putInt(String key, int value, Context ctx) {
SharedPreferences sp = ctx.getSharedPreferences("config",
Context.MODE_PRIVATE);
sp.edit().putInt(key, value).commit();
} public static int getInt(String key, int defValue, Context ctx) {
SharedPreferences sp = ctx.getSharedPreferences("config",
Context.MODE_PRIVATE);
return sp.getInt(key, defValue);
} public static void remove(String key, Context ctx) {
SharedPreferences sp = ctx.getSharedPreferences("config",
Context.MODE_PRIVATE);
sp.edit().remove(key).commit();
}
}

最新文章

  1. XML简介与CDATA解释
  2. 移动手机端H5无缝间歇平滑向上滚动js代码
  3. install sun java in ubuntu
  4. 51nod平均数
  5. golang channel buffer
  6. shell 内网主机存活探测器
  7. WSO2 Stratos手册
  8. httpclient 302 重定向
  9. 【转】 iOS学习之sqlite的创建数据库,表,插入查看数据
  10. hadoop1.2.1+hbase0.90.4+nutch2.2.1+elasticsearch0.90.5配置(伪分布式)
  11. Linux系统挂载操作mount详解
  12. Golang源码探索(三) GC的实现原理
  13. PHPstorm 2017激活
  14. shell脚本修改文本中匹配行之前的行的方法
  15. python问题:AttributeError: 'module' object has no attribute 'SSL_ST_INIT'(转)
  16. C# 深浅复制 MemberwiseClone
  17. maven名词解释
  18. Contiki源码+原理+功能+编程+移植+驱动+网络(转)
  19. loadrunner12: Error -27492: "HttpSendRequest" failed, Windows error code=8
  20. 使用openssl生成双向加密证书(转)

热门文章

  1. iOS开发~UI布局(二)storyboard中autolayout和size class的使用详解
  2. 真机测试时的错误:No matching provisioning profiles found
  3. IOS项目集成ShareSDK实现第三方登录、分享、关注等功能。
  4. 使用CocoaPods管理第三方开源类库
  5. XCode升级到7后,规范注释生成器VVDocumenter插件没有用了,怎么办?
  6. [转]Linux下的Makefile
  7. python sorted
  8. Effective Java 14 In public classes, use accessor methods, not public fields
  9. Go对OO的选择
  10. 关于统计变换(CT/MCT/RMCT)算法的学习和实现