-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathAbSharedUtil.java
More file actions
61 lines (48 loc) · 1.86 KB
/
AbSharedUtil.java
File metadata and controls
61 lines (48 loc) · 1.86 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
package com.ab.util;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import com.ab.global.AbAppConfig;
//TODO: Auto-generated Javadoc
/**
* © 2012 amsoft.cn
* 名称:AbSharedUtil.java
* 描述:保存到 SharedPreferences 的数据.
*
*/
public class AbSharedUtil {
private static final String SHARED_PATH = AbAppConfig.SHARED_PATH;
public static SharedPreferences getDefaultSharedPreferences(Context context) {
return context.getSharedPreferences(SHARED_PATH, Context.MODE_PRIVATE);
}
public static void putInt(Context context,String key, int value) {
SharedPreferences sharedPreferences = getDefaultSharedPreferences(context);
Editor edit = sharedPreferences.edit();
edit.putInt(key, value);
edit.commit();
}
public static int getInt(Context context,String key) {
SharedPreferences sharedPreferences = getDefaultSharedPreferences(context);
return sharedPreferences.getInt(key, 0);
}
public static void putString(Context context,String key, String value) {
SharedPreferences sharedPreferences = getDefaultSharedPreferences(context);
Editor edit = sharedPreferences.edit();
edit.putString(key, value);
edit.commit();
}
public static String getString(Context context,String key) {
SharedPreferences sharedPreferences = getDefaultSharedPreferences(context);
return sharedPreferences.getString(key,null);
}
public static void putBoolean(Context context,String key, boolean value) {
SharedPreferences sharedPreferences = getDefaultSharedPreferences(context);
Editor edit = sharedPreferences.edit();
edit.putBoolean(key, value);
edit.commit();
}
public static boolean getBoolean(Context context,String key,boolean defValue) {
SharedPreferences sharedPreferences = getDefaultSharedPreferences(context);
return sharedPreferences.getBoolean(key,defValue);
}
}