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再次此啓動時,帳號、密碼、記住密碼的狀態就會自動添加上去了