中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

SharedPreferences工具類

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
import java.util.Map;
import java.util.Set;
 
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
 
/**
 * SharedPreferences工具類
 * @author zouyb
 *
 */
public class SharedPreferencesUtil {
 
    private SharedPreferences sp;
    private Editor editor;
    private String name = "mosjoy_chat";
    private int mode = Context.MODE_PRIVATE;
 
    public SharedPreferencesUtil(Context context) {
        this.sp = context.getSharedPreferences(name, mode);
        this.editor = sp.edit();
    }
     
    /**
     * 創(chuàng)建一個(gè)工具類,默認(rèn)打開名字為name的SharedPreferences實(shí)例
     * @param context
     * @param name   唯一標(biāo)識(shí)
     * @param mode   權(quán)限標(biāo)識(shí)
     */
    public SharedPreferencesUtil(Context context, String name, int mode) {
        this.sp = context.getSharedPreferences(name, mode);
        this.editor = sp.edit();
    }
 
    /**
     * 添加信息到SharedPreferences
     *
     * @param name
     * @param map
     * @throws Exception
     */
    public void add(Map<String, String> map) {
        Set<String> set = map.keySet();
        for (String key : set) {
            editor.putString(key, map.get(key));
        }
        editor.commit();
    }
 
    /**
     * 刪除信息
     *
     * @throws Exception
     */
    public void deleteAll() throws Exception {
        editor.clear();
        editor.commit();
    }
 
    /**
     * 刪除一條信息
     */
    public void delete(String key){
        editor.remove(key);
        editor.commit();
    }
 
    /**
     * 獲取信息
     *
     * @param key
     * @return
     * @throws Exception
     */
    public String get(String key){
        if (sp != null) {
            return sp.getString(key, "");
        }
        return "";
    }
 
    /**
     * 獲取此SharedPreferences的Editor實(shí)例
     * @return
     */
    public Editor getEditor() {
        return editor;
    }
}

標(biāo)簽: 權(quán)限

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:Android縮放圖片 Matrix

下一篇:Android 獲取屏幕分辨率大小 獲取屏幕寬高