新建配置文件类

/**
* 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的更多相关文章

  1. 利用SharedPreferences完成记住账号密码的功能

    利用SharedPreferences完成记住账号密码的功能 效果图: 记住密码后,再次登录就会出现账号密码,否则没有. 分析: SharedPreferences可将数据存储到本地的配置文件中 Sh ...

  2. android 文件存储&SharedPreferences

    一.文件存储 文件存储主要是I/O流的操作,没什么好说的,需要注意的是保存文件的各个目录. 下面为常用的目录: public static File getInFileDir(Context cont ...

  3. Android——配置文件的保存SharedPreferences进行数据存储

    很多时候我们开发的软件需要向用户提供软件参数设置功能,例如我们常用的QQ,用户可以设置是否允许陌生人添加自己为好友.对于软件配置参数的保存,如果是window软件通常我们会采用ini文件进行保存,如果 ...

  4. Android之SharedPreferences数据存储

    一.SharedPreferences保存数据介绍 如果有想要保存的相对较小键值集合,应使用SharedPreferences API.SharedPreferences对象指向包含键值对的文件并提供 ...

  5. SharedPreferences漏洞, 无法避免,所以不要在里面存储敏感信息

     1. SharedPreferences漏洞, 无法避免,所以不要在里面存储敏感信息2. 数据存储检测,content://com.starcor.launcherInfo/deviceInfo&q ...

  6. 缓存AsimpleCache -- 解决Android中Sharedpreferences无法存储List数据/ASimpleCache

    Sharedpreferences想必大家在项目中都经常会用到,但是如果需要在本地需要存储比较多的数据,存储一个集合的时,发现Sharedpreferences并不 是那么好使了. 分析 如果需要在本 ...

  7. sharedPreferences的用法

    做软件开发应该都知道,很多软件会有配置文件,里面存放这程序运行当中的各个属性值,由于其配置信息并不多,如果采用数据库来存放并不划算,因为数据库连 接跟操作等耗时大大影响了程序的效率,因此我们使用键值这 ...

  8. android中sharedPreferences的用法

    SharedPreferences介绍:   做软件开发应该都知道,很多软件会有配置文件,里面存放这程序运行当中的各个属性值,由于其配置信息并不多,如果采用数据库来存放并不划算,因为数据库连接跟操作等 ...

  9. android数据存储之SharedPreferences

    一.SharedPreferences简介      (1)SharedPreferences是Android平台上一个轻量级的存储类,用来保存应用的一些常用配置,比如Activity状态,Activ ...

随机推荐

  1. XAML parser exception

    To debug xaml exception: Visual Studio -> Debug -> Exception -> Common Language Runtime Exc ...

  2. django1.9 创建数据表

    1.在setting.py 中注册app: 2.编写models.py 文件创建表结构: (生成的表默认是: app名称_定义的表面  ) 3.执行命令: python manage.py check ...

  3. Js特效--模仿滚动条(兼容IE8+,FF,Google)

    <html> <head> <style> *{margin:0px;padding:0px;} #box{width:200px;height:500px;pos ...

  4. SDWebImage笔记

    SDWebImage托管在github上.https://github.com/rs/SDWebImage 这个类库提供一个UIImageView类别以支持加载来自网络的远程图片.具有缓存管理.异步下 ...

  5. smartlink

    链接:https://www.zhihu.com/question/21783165/answer/20323202 Wi-Fi本身是属于固定频段上的TDD通讯机制,目前尚用的也就是2.4G和5.8G ...

  6. jquery-validation 使用

    jquery-validation 使用 一.用前必备 官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: ...

  7. IOS第一天

    第一天(hello world) 1>UIView所有的控件都继承UIView,倒位置,宽度和高度..UIButton UILable 2>UIViewController .h 是声明属 ...

  8. java常用工具类

    http://www.cnblogs.com/langtianya/p/3875124.html

  9. String-原型属性(练习)

    1.js部分/* *字符串新功能,添加一个字符串转成数组. *返回一个数组 */String.prototype.toCharArray = function(){ //定义一个数组 var chs ...

  10. JavaBean组件的基本使用-语法

    <jsp:useBean id="实例化对象名称" scope="保存范围" class="包.类名"> </jsp:us ...