Akari Akari - 4 years ago 109
Android Question

how to know how many shared preference in shared preferences in android

I want to know how many shared preference in my shared preferences which are found in the file explorer by coding , is there any method to return the total number of shared preferences ?

enter image description here

Answer Source

To get the number of entries you can use


To retrieve all the keys you stored previously you can use keySet(), as shown in the following snippet:

SharedPreferences prefs = this.getSharedPreferences("myshared", Context.MODE_PRIVATE);
Map<String,?> entries = prefs.getAll();
Set<String> keys = entries.keySet();
for (String key : keys) {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download