Here is my code.
SharedPreferences sharedPreferences = getSharedPreferences(values,
MODE_PRIVATE);
str1开发者_如何学Python = sharedPreferences.getString("lu121", "test");
str2 = sharedPreferences.getString("lp5151", "test");
et_username.setText(str1);
et_pass.setText(str2);
by default str1 and str2 should have values of test but when i open the android application the edittexts are not set as test instead i see a blank. Is there something wrong with my code?
You need to call commit()
to save the values (you didn't include any code where you are writing.
...
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("lu", "testlu");
editor.putString("lp", "testlp");
editor.commit();
精彩评论