Can someone please help me see what I’ve overlooked here?
The thing is, these values won’t commit to persistent storage – .commit() returns true and everything, but the values are simply not there…
public void onPause() {
super.onPause();
if (timerStarted) {
// Save the values
settings.edit().putInt(getString(beer).toString(), savedVal_beer);
settings.edit().putInt(getString(lightBeer).toString(), savedVal_ltBeer);
settings.edit().putInt(getString(strongBeer).toString(), savedVal_stBeer);
settings.edit().putInt(getString(wine).toString(), savedVal_wine);
settings.edit().putInt(getString(fortifiedWine).toString(), savedVal_fortWine);
settings.edit().putInt(getString(liqeur).toString(), savedVal_liqeur);
settings.edit().putInt(getString(spirits).toString(), savedVal_spirits);
if (counterStarted) {
settings.edit().putString(getString(R.string.key_counter_lastTypeUsed), selectedType);
}
settings.edit().commit();
if (settings.edit().commit()) {
Toast.makeText(this, "saved", Toast.LENGTH_SHORT).show();
}
}
}
I have added a breakpoint at the end and used the debugger to verify that the variables to be stored are indeed there, however when I use adb to pull the sharedPrefs xml-file, none of the values have actually been saved…
timerStarted and counterStarted are both true, as they should be.
You have to use one
edit()call, only. And remove the dual call tocommit().