title: MultiSelectListPreference defaultValues not working
body: <p>I have a project that I am building in Android Studio. I've added the prebuilt preference screen with fragments which compiles and runs fine. I added a MultiSelectListPreference to one of the preference screens which displays fine and stores preference settings. However, the defaultValue is not working whether I add it via Java or XML. I have read the scores of other questions about how to do this. I know how. My question is what could cause it not to work as intended?</p>
  
  <p>pref_general.xml</p>
  
  <pre><code>&lt;MultiSelectListPreference
      android:key="@string/pref_key_starting_addresses"
      android:summary="@string/pref_description_addresses"
      android:title="@string/pref_title_addresses"
      android:entries="@array/empty_array"
      android:entryValues="@array/empty_array" /&gt;
  </code></pre>
  
  <p>PreferenceActivity.java</p>
  
  <pre><code>/**
   * This method autopopulates a MultiSelectListPreference with array values
   * loaded from XML.
   */
  private void populateMultiSelectListPreference() {
      List&lt;TypedArray&gt; origins = ResourceHelper.getMultiTypedArray(mContext, "origins");
      CharSequence[] entries = new CharSequence[origins.size()];
      CharSequence[] values = new CharSequence[origins.size()];
      int counter = 0;
      for (TypedArray item : origins) {
          entries[counter] = item.getString(0);
          values[counter] = String.valueOf(counter);
          counter++;
      }
  
      final MultiSelectListPreference lp = (MultiSelectListPreference) findPreference(getString(R.string.pref_key_starting_addresses));
      lp.setEntries(entries);
      lp.setDefaultValue(values);
      lp.setEntryValues(values);
  }
  </code></pre>
  
  <p>arrays.xml</p>
  
  <pre><code>&lt;string-array name="empty_array" /&gt;
  
  &lt;!-- a number of these are used to generate the MultiSelectListPreference
       titles and entry values--&gt;
  &lt;array name="origins_0"&gt;
      &lt;item&gt;Text used for title&lt;/item&gt;
      &lt;item&gt;data 1&lt;/item&gt;
      &lt;item&gt;data 2&lt;/item&gt;
  &lt;/array&gt;
  </code></pre>
  
  <p>I know that everything is working properly because debugging shows that <code>values</code> contains a valid Set and saving preferences works fine. This means that <code>lp.setEntryValues(values)</code> works and that <code>values</code> is a properly formatted Set. However, <code>lp.setDefaultValue(values)</code> has no effect. The checkboxes are all unchecked at first run. My goal is to have them all selected by default.</p>
  
  <p>Yes, I have used the <code>Clean and rerun 'app'</code> command from Android Studio's Run menu between tests. Additionally, I've cleared the app cache manually on the device.</p>
  
  <p>[EDIT]</p>
  
  <p>With suggestions in comments, I have also tried the following modification.</p>
  
  <pre><code>private void populateMultiSelectListPreference() {
      List&lt;TypedArray&gt; origins = ResourceHelper.getMultiTypedArray(mContext, "origins");
      CharSequence[] entries = new CharSequence[origins.size()];
      CharSequence[] values = new CharSequence[origins.size()];
      Set&lt;String&gt; defaults = new HashSet&lt;&gt;();
      int counter = 0;
      for (TypedArray item : origins) {
          entries[counter] = item.getString(0);
          values[counter] = String.valueOf(counter);
          defaults.add(String.valueOf(counter));
          counter++;
      }
  
      final MultiSelectListPreference lp = (MultiSelectListPreference) findPreference(getString(R.string.pref_key_starting_addresses));
      lp.setEntries(entries);
      lp.setEntryValues(values);
      lp.setDefaultValue(defaults);
  }
  </code></pre>