我想保存用户凭据使用sharedpreferences,我通过这种方式这样做,但它不工作保存凭据sharedpreferences
public class MainActivity extends Activity {
public EditText UserName;
public EditText Password;
public Button mButton;
public String user_name;
public String pass_word;
public CheckBox mCheckSavePassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
UserName = (EditText) findViewById(R.id.textUserName);
Password = (EditText) findViewById(R.id.textPassword);
mButton = (Button) findViewById(R.id.buttonLogin);
mCheckSavePassword = (CheckBox) findViewById(R.id.checkSavePassword);
mCheckSavePassword = (CheckBox) findViewById(R.id.checkSavePassword);
SharedPreferences.Editor preferencesEditor = preferences.edit();
preferencesEditor.putString("prefUserName", user_name);
if(mCheckSavePassword.isChecked()) {
preferencesEditor.putString("prefPassword", pass_word);
}
preferencesEditor.putBoolean("prefSavePassword", mCheckSavePassword.isChecked());
preferencesEditor.apply();
}
你怎么知道它不工作? – 2014-11-05 19:41:30
,因为当我再次重新输入时,需要填写凭证 – Andrew 2014-11-05 19:46:40
发布您正在使用的代码来读取首选项值,以便我们可以看到什么不起作用。 – 2014-11-05 19:47:55