I’ve placed a preferences file ‘xml/sleeppreferences.xml’ into a tabSpec, with the idea that that is the preferences for that part of the app and there will be other preference files for other parts.
This seems to work ok. I make a preference change, close the emulator, re-run the app, go back to the preference page, and the preference is what I had set it to.
But when I click to another tab, where I want to use the value of that preference, it all goes wrong.
I’ve looked high and low, but cannot find an answer.
This is an excerpt of the code:
public static final String PREF_FILE_NAME = "sleeppreferences";
:
:
:
SharedPreferences prefs = getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE);
String test=prefs.getString("editTextPref", "unset");
with “unset” being the default response if it doesn’t find anything.
It always returns “unset”
As I say, I’ve looked all over, and the code I’m using seems to be the correct code. So what’s going on?
Thanks
Dave
Try using the GetSharedPreferences of the context class. Something like this:
I think this should work as well: