Reputation: 61
My app have had many releases and some of the earlier version sharedPreferences are useless. What would be the best way to have the app itself sorting out the one that are still used and remove the unused one ? Basically it would be like parsing the preferences XML's to extract the current android::key and by getting all preferences present on the device remove the one not being anymore in an XML.
Not sure I am very clear, but I have lot's of shared preferences not used anymore and having to establish the list manually can be source of problem.
Any hint would be great, Thanks a lot
Upvotes: 1
Views: 925
Reputation: 73753
you can go through the keys one by one removing any that you dont use anymore like this
Map<String,?> prefs = pref.getAll();
for(Map.Entry<String,?> prefToReset : prefs.entrySet()){
if(prefToReset.getKey().equals("someKey")){
pref.edit().remove(prefToReset.getKey()).commit();
}
}
though there really is no performance benefit from doing this really
Upvotes: 1