How to get all keys of SharedPreferences programmatically in Android?
SharedPreferences
has the method getAll()
that returns a Map<String, ?>
. From the Map you can retrieve easily the keys with keySet()
and the key/value mappings with entrySet()
:
Map<String, ?> allEntries = prefA.getAll();for (Map.Entry<String, ?> entry : allEntries.entrySet()) { Log.d("map values", entry.getKey() + ": " + entry.getValue().toString());}
What you can do is use getAll() method of SharedPreferences and get all the values in Map and then you can easily iterate through them:
Map<String,?> keys = prefs.getAll();for(Map.Entry<String,?> entry : keys.entrySet()){ Log.d("map values",entry.getKey() + ": " + entry.getValue().toString()); }
For more, you can check PrefUtil.java's dump() implementation with this link.
Use the getAll() method of android.content.SharedPreferences
.
Map<String, ?> map = sharedPreferences.getAll();