8

PreferenceManager.setDefaultValues(context,R.xml.preferences,false)用来在我的应用程序中设置首选项的默认值,我注意到如果我添加一个新的首选项,那么我PreferenceFragment不会显示它的默认值,即使它是在preferences.xml中设置的。

这是因为我将readAgain指定为 false 吗?

我知道我可以简单地试试看,但我只是想确定readAgain是为此目的,即重新读取默认值不是为了重新设置用户设置,而是设置新属性的默认值. 如果这正是readAgain标志的目的,那么您能否给我一个理由不总是将readAgain设置为 true,因为它不会重置用户首选项?

4

1 回答 1

7

Setting the readagain flag to true will ensure that all unset-default values are set again. That's the summary.

Setting the readagain will cause extra overhead since basically it means that, the code will go through the entire SharedPreference once more to check them. With the readAgain false,all it does is to check whether the file ( has_set_default_values.xml ) which is used as a marker for setting default values is present or not.

In any case, It won't set any values that are already set .

于 2012-05-14T08:49:48.893 回答