PreferenceManager.setDefaultValues ​​readAgain parameter and new settings

I use PreferenceManager.setDefaultValues(context,R.xml.preferences,false) to set default values ​​for parameters in my application and I noticed that if I add a new preference then my PreferenceFragment will not show the default value for it. even if it is installed in preferences.xml ..

Is this because I am specifying readAgain as false?

I know that I can just try and see, but I just wanted to be sure that readAgain is for this purpose, that is, re-read the default values ​​so as not to reset user settings, but to set new properties' default values. If this is the purpose of the readAgain flag, can you give me a reason not to always set readAgain to true, given that user settings are not reset?

+6
source share
1 answer

Setting the readagain flag to true will cause all unset-default values ​​to be set again. This is a summary.

Installing readagain will readagain additional overhead, since it basically means that the code will go through the entire SharedPreference again to check them. With readagain false, all it does is check if a file ( has_set_default_values.xml ) is present , which is used as a marker for setting default values.

In any case, it will not set the values ​​that are already set.

+4
source

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


All Articles