I have a problem with the SharedPreferences
If I want to save two different values. I tried with this code:
SharedPreferences sharedPref = getSherlockActivity().getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(getString(R.string.SavedStartSilentHour), hour);
editor.commit();
editor.putInt(getString(R.string.SavedStartSilentMinute), min);
editor.commit();
// One editor.commit() is enough
If I run this code the first value is overwritten with the seccond value. If I delte the second part the value is saved correctly. Why is that?
Your code seems perfect!
You could simplify the thing by committing all the stuff after all the "puts" operations. Although I don't think that this could be your problem...
Just make sure SavedStartSilentHour
and SavedStartSilentMinutes
xml's defined values are correctly defined, i.e., if they are the same of course they will be overwritten. (This is the only one thing that makes any sense to me considering your code).
Let mew know of your progress ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With