How to find out how many common preferences in common preferences in android

I want to know how many common preferences in my general preferences are contained in the file explorer by encoding, is there a way to return the total number of general settings?

enter image description here

+6
source share
3 answers

To get the number of records you can use

sharedPreferencesInstance.getAll().size() 

To get all the keys you saved earlier, 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) { } 
+6
source

In your activity, try the following:

 SharedPreferences prefs = this.getSharedPreferences("your.package", Context.MODE_PRIVATE); int howMany = prefs.getAll().size(); 
+7
source

Not sure if you are looking at something like this . If it's just size, you can just do

 SharedPreferences pref = getSharedPreferences(<NAME>, <MODE>); pref.getAll().size(); 
+1
source

Source: https://habr.com/ru/post/948462/


All Articles