01.
public
class
UserHelper {
02.
Context context;
03.
SharedPreferences sharedPerfs;
04.
Editor editor;
05.
06.
07.
static
String perfsName =
"UserHelper"
;
08.
static
int
perfsMode =
0
;
09.
10.
public
UserHelper(Context context) {
11.
this
.context = context;
12.
this
.sharedPerfs =
this
.context.getSharedPreferences(perfsName, perfsMode);
13.
this
.editor = sharedPerfs.edit();
14.
}
15.
16.
public
void
createSession(String key) {
17.
editor.putBoolean(
"isLogin"
,
true
);
18.
editor.putString(
"userID"
, key);
19.
editor.commit();
20.
}
21.
22.
public
void
deleteSession() {
23.
editor.clear();
24.
editor.commit();
25.
}
26.
27.
public
boolean
isLogin() {
28.
return
sharedPerfs.getBoolean(
"isLogin"
,
false
);
29.
}
30.
31.
public
String getUserID() {
32.
return
sharedPerfs.getString(
"userID"
,
null
);
33.
}
34.
}