配置文件之SharedPreferences
2024-09-23 20:16:36
新建配置文件类
/**
* 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());
最新文章
- mysql习惯及主从复制参数设置
- Visual Studio 2010 实用功能:使用web.config发布文件替换功能
- FU-A分包方式,以及从RTP包里面得到H.264数据和AAC数据的方法。。
- 获取和设置select和checkbox的值
- linux ptrace II
- 小结css2与css3的区别
- 编译 ORB_SLAM2 (一)
- Error:No such property: GROUP for class: org.gradle.api.publication.maven.internal.deployer.DefaultGroovyMavenDeployer
- 为UWP应用开启回环访问权限
- golang 二进制转十进制实现方式
- Python Cook函数笔记 【第一章】
- Modbus CRC 16 (C#)
- Unity shader 官网文档全方位学习(一)
- is interest important?
- IntelliJ IDEA 14.1.4破解方法-通过程序根据用户名生成注册码
- php连接微软MSSQL(sql server)完全攻略
- DNS_PROBE_FINISHED_NXDOMAIN 问题解决
- 180801-Spring之定时任务基本使用篇
- 【spring mvc】application context中【bean】的生命周期
- 在单片机上实现UDP