新建配置文件类
/** * 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());
时间: 2024-10-08 16:34:02