-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpUtil.java
More file actions
62 lines (53 loc) · 1.6 KB
/
SpUtil.java
File metadata and controls
62 lines (53 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
/**
* 有关 sharedPerference的工具类
*
* @author yemeng
*
*/
public class SpUtil {
private static final String NAME = BuildConfig.APPLICATION_ID;
private static SharedPreferences sp = BaseApplication.application
.getSharedPreferences(NAME, Context.MODE_PRIVATE);
// set方法
public static void setStringSharedPerference(String key, String value) {
Editor editor = sp.edit();
editor.putString(key, value);
editor.commit();
}
public static void setIntSharedPerference(String key, int value) {
Editor editor = sp.edit();
editor.putInt(key, value);
editor.commit();
}
public static void setLongSharedPerference(String key, Long value) {
Editor editor = sp.edit();
editor.putLong(key, value);
editor.commit();
}
public static void setBooleanSharedPerference(String key, boolean value) {
Editor editor = sp.edit();
editor.putBoolean(key, value);
editor.commit();
}
// get方法
public static String getStringSharedPerference(String key, String value) {
return sp.getString(key, value);
}
public static int getIntSharedPerference(String key, int value) {
return sp.getInt(key, value);
}
public static long getLongSharedPerference(String key, long value) {
return sp.getLong(key, value);
}
public static boolean getBooleanSharedPerference(String key, boolean value) {
return sp.getBoolean(key, value);
}
public static void clearAll(){
SharedPreferences.Editor editor = sp.edit();
editor.clear();
editor.commit();
}
}