今天用昨天学的sharepreferences来完成之前记住密码的操作
//宣告
private SharedPreferences preferences;
preferences = getSharedPreferences("config",MODE_PRIVATE);
//读取上次有没有勾选记住密码
boolean remember = preferences.getBoolean("remember", false);
if(remember){
reload();
}
//reload
private void reload() {
et_phone.setText(preferences.getString("phone",""));
et_password.setText(preferences.getString("password",""));
ck_remember.setChecked(true);
}
//如果有勾选就把手机号码跟密码记住下次使用
//如果没有清除资料
SharedPreferences.Editor edit = preferences.edit();
if(ck_remember.isChecked()){
edit.putString("phone",et_phone.getText().toString());
edit.putString("password",et_password.getText().toString());
edit.putBoolean("remember",true);
edit.commit();
}else{
edit.remove("phone");
edit.remove("password");
edit.remove("remember");
edit.commit();
}
}