Skip to content

Commit 3249737

Browse files
committed
see 04/27 log
1 parent 843ac1a commit 3249737

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

utilcode/src/main/java/com/blankj/utilcode/util/SPUtils.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ public final class SPUtils {
3030
* @return the single {@link SPUtils} instance
3131
*/
3232
public static SPUtils getInstance() {
33-
return getInstance("");
33+
return getInstance("", Context.MODE_PRIVATE);
34+
}
35+
36+
/**
37+
* Return the single {@link SPUtils} instance
38+
*
39+
* @param mode Operating mode.
40+
* @return the single {@link SPUtils} instance
41+
*/
42+
public static SPUtils getInstance(final int mode) {
43+
return getInstance("", mode);
3444
}
3545

3646
/**
@@ -40,10 +50,21 @@ public static SPUtils getInstance() {
4050
* @return the single {@link SPUtils} instance
4151
*/
4252
public static SPUtils getInstance(String spName) {
53+
return getInstance(spName, Context.MODE_PRIVATE);
54+
}
55+
56+
/**
57+
* Return the single {@link SPUtils} instance
58+
*
59+
* @param spName The name of sp.
60+
* @param mode Operating mode.
61+
* @return the single {@link SPUtils} instance
62+
*/
63+
public static SPUtils getInstance(String spName, final int mode) {
4364
if (isSpace(spName)) spName = "spUtils";
4465
SPUtils spUtils = SP_UTILS_MAP.get(spName);
4566
if (spUtils == null) {
46-
spUtils = new SPUtils(spName);
67+
spUtils = new SPUtils(spName, mode);
4768
SP_UTILS_MAP.put(spName, spUtils);
4869
}
4970
return spUtils;
@@ -53,6 +74,10 @@ private SPUtils(final String spName) {
5374
sp = Utils.getApp().getSharedPreferences(spName, Context.MODE_PRIVATE);
5475
}
5576

77+
private SPUtils(final String spName, final int mode) {
78+
sp = Utils.getApp().getSharedPreferences(spName, mode);
79+
}
80+
5681
/**
5782
* Put the string value in sp.
5883
*

0 commit comments

Comments
 (0)