Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all keys of SharedPreferences programmatically in Android?

How to get all keys in SharedPreferences, not the value of the preference just key only?

prefA = getSharedPreferences("MyAttack", MODE_PRIVATE); prefB= getSharedPreferences("MySkill", MODE_PRIVATE); 
like image 647
Piolo Opaw Avatar asked Feb 28 '14 07:02

Piolo Opaw


1 Answers

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()); }  
like image 185
Blackbelt Avatar answered Oct 19 '22 09:10

Blackbelt