1

I know it's been asked before, but it doesn't seem to work for me.

I have an XML file preferences.xml in the folder res\xml. It contains an optionscreen like so:

<PreferenceScreen>
  <EditTextPreference
                android:name="prfEmail"
                android:summary="Your account's e-mail address"
                android:title="E-mail"
                android:key="prfEmail" />
</PreferenceScreen>

I can make an activity from it and it shows fine. Now I'd like to read values from these preferences, but I can't seem to find it. In another activity I do:

SharedPreferences appSharedPrefs;
appSharedPrefs = getSharedPreferences("preferences",Activity.MODE_PRIVATE);
String restoredText = appSharedPrefs.getString("prfEmail",null);

Whan I'd like to print this value it gives null back. What am I doing wrong?

PoeHaH
  • 1,936
  • 3
  • 28
  • 52

1 Answers1

2

The app preferences are stored in the default SharedPreferences. You can access them with :

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
Dalmas
  • 26,409
  • 9
  • 67
  • 80