title: Android Get Keys from preferences.xml
body: <p>I have a <code>PreferencesActivity</code> that shows a <code>preferences.xml</code> with checkboxes.</p>
  
  <p><code>preferences.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  &lt;PreferenceCategory android:title="Keywords"&gt;
      &lt;CheckBoxPreference android:key="Essen" 
                          android:title="Essen" 
                          android:selectable="true" 
                          android:enabled="true"
                          android:persistent="false"&gt;
      &lt;/CheckBoxPreference&gt;
      &lt;CheckBoxPreference android:key="Kleidung" 
                          android:title="Kleidung" 
                          android:selectable="true" 
                          android:enabled="true"
                          android:persistent="false"&gt;
      &lt;/CheckBoxPreference&gt;
  &lt;/PreferenceCategory&gt;
  &lt;/PreferenceScreen&gt;
  </code></pre>
  
  <p>PreferencesActivity:</p>
  
  <pre><code>public class PreferencesViewController extends PreferenceActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          addPreferencesFromResource(R.xml.preferences);
      }
  }
  </code></pre>
  
  <p>Now in a different <code>ListActivity</code> I want to show all Keys/Titles from the checked checkboxes.</p>
  
  <p>I try to access the Preferences with</p>
  
  <pre><code>SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>SharedPreferences prefs = getSharedPreferences("mypackage_preferences", 0);
  </code></pre>
  
  <p>But both dont really work.</p>
  
  <p>When I call <code>prefs.getAll().size()</code> the result is 0.</p>
  
  <p>I can access the Keys/Title with <code>getPreferenceScreen().getPreference(i).…</code> but it doesn't work from a different <code>Activity</code>, only from the <code>PreferenceActivity</code>.</p>
  
  <p>Does anybody have a solution how to get this work?</p>