首页 > 其他 > 详细

SharedPreferences保存用户偏好参数

时间:2016-05-07 13:22:07      阅读:127      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!