• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
浅时光
我喜欢,驾驭着代码在风驰电掣中创造完美!我喜欢,操纵着代码在随必所欲中体验生活!我喜欢,书写着代码在时代浪潮中完成经典!每一段新的代码在我手中诞生对我来说就象观看刹那花开的感动!
博客园    首页    新随笔    联系   管理    订阅  订阅

配置文件之SharedPreferences

新建配置文件类

/**
 * 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());

 

posted @ 2015-09-21 18:44  浅时光  阅读(321)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3