I think this question is more related to why
PreferenceManager.getDefaultSharedPreferences(this).getAll()
returns a blank / inconsistent display than with how to iterate over a standard java map. The android doc is actually not very clear what is going on here, but basically it looks like the first call on
PreferenceManager.setDefaultValues(this, R.xml.preferences,false)
- this is what you must call to initialize preferences when starting the application - it creates some kind of cached version of your preferences, which leads to the steady conversion of future changes to the xml settings file, i.e. causes the mismatch that you described in your question.
to reset this "cached object", follow these steps (which you can find from the link above):
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.edit().clear(); PreferenceManager.setDefaultValues(this, R.xml.preferences, true);
rmanna Feb 14 '13 at 17:05 2013-02-14 17:05
source share