Android SharedPreferences 工具类
Android 大约 1398 字工具类
public class SpUtil {
private final SharedPreferences mSp;
private final SharedPreferences.Editor mEditor;
public SpUtil (Context context) {
mSp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
mEditor = mSp.edit();
}
/*--------------- 读 ---------------*/
/**
* 读取字符信息
* @param key
* @param defValue
* @return
*/
public String getString(String key, String defValue) {
return mSp.getString(key, defValue);
}
/**
* 读取整型
*/
public int getInt(String key, int defValue) {
return mSp.getInt(key, defValue);
}
/**
* 读取布尔型
*/
public boolean getBoolean(String key, boolean defValue) {
return mSp.getBoolean(key, defValue);
}
/*--------------- 写 ---------------*/
/**
* 写入string
* @param key
* @param value
*/
public void putString(String key, String value) {
mEditor.putString(key, value);
mEditor.commit();
}
/**
* 写入int
* @param key
* @param value
*/
public void putInt(String key, int value) {
mEditor.putInt(key, value);
mEditor.commit();
}
/**
* 写入boolean
* @param key
* @param value
*/
public void putBoolean(String key, boolean value) {
mEditor.putBoolean(key, value);
mEditor.commit();
}
}
阅读 3750 · 发布于 2019-04-12
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓
昵称:
随便看看
换一批
-
Android ContentProvider批量插入数据阅读 4241
-
Docker 部署 Redis阅读 1129
-
Redis 使用 bigkeys 命令查找大 key阅读 5006
-
VisualVM 监控注册成 Windows 服务的 Tomcat 之 jstatd 方式一阅读 2143
-
Java JMX MemoryMXBean阅读 153
-
PHP 判断函数、类、方法、属性、数组中的 key 是否存在阅读 3864
-
PostgreSQL 查看时区阅读 9386
-
IDEA 新主题 UI阅读 406
-
Elasticsearch 监控运行状态阅读 2470
-
JMeter 使用 Loop Controller 进行循环请求阅读 2170