码迷,mamicode.com
首页 > 其他好文 > 详细

SharedPreferences保存用户偏好参数

时间:2016-05-07 13:22:16      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

package com.example.administrator.myapplication;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Administrator on 2016/5/7 0007.
 */
public class BrowserSP {
    private Context context;
    private SharedPreferences sp;
    private SharedPreferences.Editor editor;
    public BrowserSP(){}
    public BrowserSP(Context context){
        this.context=context;
        sp=this.context.getSharedPreferences("sp",Context.MODE_PRIVATE);
        editor=sp.edit();
    }
    public void save(String key,String value){
        editor.putString(key,value);
        editor.commit();
    }
    public String read(String key){
        return sp.getString(key,"");
    }
    public void remove(String key){
        editor.remove(key);
        editor.commit();
    }
    public boolean keyExists(String key){
        return sp.contains(key);
    }
}

 

SharedPreferences保存用户偏好参数

标签:

原文地址:http://www.cnblogs.com/zqxLonely/p/5467876.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!