doum
6 天以前 2b287056e2f59518888d05a1bbc7e5a55fbd84d5
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
package com.doumee.keyCabinet.ui.face;
 
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
 
/**
 * SharedPreferences
 * Created by liujialu on 2020/02/11.
 */
 
public class ShareManager {
    // 定义存储用户名字段
    private static final String SP_DB_STATE = "db_state";
 
    private static ShareManager instance;
    private SharedPreferences sp;
    private Context mContext;
 
    private ShareManager(Context context) {
        this.mContext = context;
        sp = PreferenceManager.getDefaultSharedPreferences(context);
    }
 
    public static synchronized ShareManager getInstance(Context context) {
        if (instance == null) {
            instance = new ShareManager(context);
        }
        return instance;
    }
 
    // 存储数据库状态
    public void setDBState(boolean state) {
        sp.edit().putBoolean(SP_DB_STATE, state).apply();
    }
    // 获取数据库状态
    public boolean getDBState() {
        return sp.getBoolean(SP_DB_STATE, false);
    }
}