我的问题:当我想保存 sharedPreference 并重新启动应用程序时,它没有加载正确的值。我的代码:
int punkteint = 0;
TextView test1;
String points;
private static String SHARED_PREF_ID = "0";
public void onCreate(Bundle savedInstanceState) {
test1 = (TextView) findViewById(R.id.test1);
SharedPreferences load = getSharedPreferences(SHARED_PREF_ID, 0);
points = load.getString("punkte", "0");
points = SHARED_PREF_ID;
test1.setText(points);
mehrPunkte();
}
public void mehrPunkte() {
punkteint++;
SHARED_PREF_ID = Integer.toString(punkteint);
SharedPreferences load = getSharedPreferences(SHARED_PREF_ID, MODE_PRIVATE);
points = load.getString("punkte", "0");
points = SHARED_PREF_ID;
test1.setText(points);
SharedPreferences save = getSharedPreferences(SHARED_PREF_ID, MODE_PRIVATE);
save.edit().putString("punkte", SHARED_PREF_ID).commit();
}
我在这里做错了什么?希望你能帮我