@Kostya, no I don't use "Wipe Data".

I don't know what the exact underlying problem was at this point but I
managed to fix things by manually deleting the sharedpreferences file
from the emulator's shared_prefs folder while in the ADB shell, and
then recreating it as an empty file using "echo -n >app_global".  Note
"app_global" is just an arbitrary name I chose for the
sharedpreferences file.  I can't be certain, but it looks like the
emulator will not recreate the sharedpreferences file if you delete it
yourself manually, like I did when I was having trouble persisting
sharedpreferences writes between emulator sessions and tried that to
fix the problem.  Now everything works fine.

-- roschler

On Apr 23, 3:28 am, Kostya Vasilyev <[email protected]> wrote:
> 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<[email protected]>  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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to