private SharedPreferences.Editor editor;
protected void onCreate(Bundle savedInstanceState) {
pref = PreferenceManager.getDefaultSharedPreferences(this);
editor = pref.edit();
//若是CheckBox为记住密码,则把帐号,密码,记住密码的状态,存储到SharedPreferences中去,而后提交
if (remberPass.isChecked()){
editor.putBoolean("rememberPass",true);
editor.putString("account",Myaccount);
editor.putString("password",MypassWord);
}else{
editor.clear();
}
editor.commit();
}
--------------------------------------------------
运行结果
若是CheckBox选择记住密码,关闭APP再次此启动时,帐号、密码、记住密码的状态就会自动添加上去了