我有一个奇怪的问题,之前从没有遇到过。当我尝试将int值保存到我的SharedPreference中,然后在其他Activity中恢复时,无论我保存了什么值(例如1),该值总是为0。
private String Number;
private String Profile;
然后在第一个Activity中将值(在本例中为“1”)保存到SharedPreferences中:
SharedPreferences a = FirstActivity.this.getSharedPreferences("a", MODE_PRIVATE);
SharedPreferences.Editor prefsEditorProfiles = a.edit();
prefsEditorProfiles.putInt(Profile, 1);
prefsEditorProfiles.putInt(Number, 1);
prefsEditorProfiles.commit();
然后在其他活动中恢复SharedPreferences:
SharedPreferences a = SecondActivity.this.getSharedPreferences("a", MODE_PRIVATE);
int ab = a.getInt(Number, 0);
应用程序显示0而不是1。我的其他SharedPreferences运行良好。我不知道问题出在哪里。