在 Activity_A 中,我有:
public static final String PREFS_NAME = "MyPrefsFile";
SharedPreference settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("hasLoggedIn", true);
editor.commit();
在 Activity_B 我有:
//changing the previously added **city** value
SharedPreferences settings = getSharedPreferences(Activity_A.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("city", myCity);
editor.commit();
在 Activity_C 我有:
SharedPreferences settings = getSharedPreferences(Activity_A.PREFS_NAME, 0);
String city = settings.getString("city", "default");
//here i am getting the previous value of **city**, not the updated 1 from Activity_B
但是一旦我重新启动应用程序,它就会给出正确的值。
我究竟做错了什么?
谢谢你