恢复代码:
final SharedPreferences settings = getSharedPreferences("pref", 0);
settings.getString("user", "");
settings.getString("pw", "");
商店代码:
SharedPreferences.Editor editor = settings.edit();
editor.putString("user", etuser.getText().toString());
editor.putString("pw", etpw.getText().toString());
editor.commit();
此代码不起作用,不会发生错误
答案 0 :(得分:2)
String s1 = settings.getString("user", "");
String s2 = settings.getString("pw", "");
我的观点是 - 您返回了所需的字符串,但您没有将其值分配给任何内容。
答案 1 :(得分:0)
editor.putString("user", etuser.getText().toString());
editor.putString("pw", etpw.getText().toString());
正如旁注,您不需要toString()
。