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