Robert,
Do you start the emulator with "Wipe data" option, by any chance?
If you are, that explains it, as wiping the data means.... well, wiping
the data.
The preferences are stored in the file system of the emulated Android
device, just like on a real phone, not directly within the host
computer's file system.
You can find the files under:
/data/data/<your package name>/shared_prefs
-- Kostya
23.04.2011 10:02, Zsolt Vasvari пишет:
No idea about the MODE_PRIVATE stuff, but I use
PreferenceManager.getDefaultSharedPreferences() and it works fiine.
Why do you need to control the file name?
On Apr 23, 12:15 pm, roschler<robert.osch...@gmail.com> wrote:
I am using the following code to save data to my Android application's
shared preferences:
private SharedPreferences getOurSharedPreferences() {
return getSharedPreferences(SHARED_PREFS_FILENAME,
MODE_PRIVATE);
}
SharedPreferences sharedPrefs = getOurSharedPreferences();
SharedPreferences.Editor editor = sharedPrefs.edit();
editor.putString(keyName, theString);
if (!editor.commit())
throw new RuntimeException("Unable to save new string.");
// Get it back as a test.
String s2 = getStringFromStorage(keyName);
Where SHARED_PREFS_FILENAME is a private final static string and
keyName is the name of whatever key I'm currently using as a field
name. The commit works fine, I don't get an exception. As you can see
I added a test that retrieves the recently committed string and when I
check it (s2) the value is fine. So I am not having any problems with
shared preferences storage during the lifetime of my app. However,
when I relaunch the application in the emulator the shared preferences
storage area is empty and I can't find the values I stored in the last
emulator session. I did some reading and as far as I can see the
stored values should persist across sessions, apparently they are
saved in an XML file belonging to the emulator. Yet I am having
problems.
Can anyone tell me why my shared preferences storage values are not
persisting between Android emulator sessions?
-- roshcler
--
Kostya Vasilyev -- http://kmansoft.wordpress.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en