天天看点

Xamarin.Android 记住账号

1.存储登陆信息

if(login_cb_user.Checked)
            {
                ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
                ISharedPreferencesEditor editor = prefs.Edit();
                editor.PutBoolean("Ck_Status", true);
                editor.PutString("UserName", UserName); 
                editor.Commit();
                editor.Apply();
            } 
            else
            {
                ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
                ISharedPreferencesEditor editor = prefs.Edit();
                editor.PutBoolean("Ck_Status", false);
                editor.PutString("UserName", null); 
                editor.Commit();
                editor.Apply();
            }      

2.读取登录信息

ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            login_cb_user.Checked = prefs.GetBoolean("Ck_Status", false);
            login_et_user.Text = prefs.GetString("UserName", null);