首页 > 其他 > 详细

配置文件之SharedPreferences

时间:2015-09-21 19:16:16      阅读:191      评论:0      收藏:0      [点我收藏+]

新建配置文件类

/**
 * Created by RongGuang 
 * 应用程序配置信息
 */
public class AppOption {
    public static final String APP_OPTION_VERSION="version";
    public static final String APP_OPTION_SERVER="server";
    public static final String APP_OPTION_STATE="state";
    public static final String APP_OPTION_USER="user";
    public static final String APP_OPTION_PASSWORD="password";

    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;

    public AppOption() {
        this.sharedPreferences = net.andy.com.Application.getContext().getSharedPreferences("boiling.option", Context.MODE_PRIVATE);
        this.editor = this.sharedPreferences.edit();
    }

    public String getOption(String key){
        return sharedPreferences.getString(key,"");
    }

    public void setOption(String key,String value){
        editor.putString(key, value);
        editor.apply();
    }

}

在相应的位置引用对象和方法即可。

 appOption.setOption(AppOption.APP_OPTION_USER, userId.getText().toString());
                            appOption.setOption(AppOption.APP_OPTION_PASSWORD, password.getText().toString());

 

配置文件之SharedPreferences

原文:http://www.cnblogs.com/rongguang/p/4826942.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!