greywolf82
greywolf82

Reputation: 22183

Default preferences values with fragments

I've got an xml file with my preferences. Inside I've got several preference fragments. Each preference fragment has got its preference xml file associated. Have I to call:

PreferenceManager.setDefaultValues(this, R.xml.settings, false);

for each xml file? The docs says that only the first call (with false parameter) is going to write the default values. Am I missing something? How to manage multiple fragments?

Upvotes: 0

Views: 142

Answers (1)

greywolf82
greywolf82

Reputation: 22183

Reply to myself:

 // we cannot call setDefaultValues for multiple fragment based XML preference files with readAgain flag set to false, so always check KEY_HAS_SET_DEFAULT_VALUES
        if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) {
            PreferenceManager.setDefaultValues(this, R.xml.frag1, true);
            PreferenceManager.setDefaultValues(this, R.xml.frag2, true);
            .......
            PreferenceManager.setDefaultValues(this, R.xml.fragN, true);
        }

Upvotes: 1

Related Questions