So I was doing some development and changed the key names (android:key) of some preferences I have in my settings.xml file. During some testing I realized that the old settings (old keys and values) were still there, even though my new settings.xml file didn’t have them anymore.
I had been doing this when my app started:
PreferenceManager.setDefaultValues(this, R.xml.settings, false);
Which isn’t removing the old settings that are no longer in my settings file.
Then tried this:
PreferenceManager.setDefaultValues(this, R.xml.settings, true);
And finally this:
PreferenceManager.getDefaultSharedPreferences(this).edit().clear();
PreferenceManager.setDefaultValues(this, R.xml.settings, true);
But the old keys/values are still there. Ok, so now I just restarted the emulator with “Clear user data” checked, so that I’m sure will do the trick. But what is the correct way to do this other than that?
What is the correct way to clear the old settings out?
After your final example, you have to do a commit.
I would recommend breaking the steps out to make it easier to read.