4

If i update my app with a new version, the sharedPreferences are gone.

LogCat says: Package de.xxx.yyy codePath changed from /data/app/de.xxx.yyy-1.apk to /data/app/de.xxx.yyy-2.apk; Retaining data and using new

The Package is the same as before.

The changes of the manifest-file are:

android:versionCode="6" -> android:versionCode="7"
android:versionName="1.6.000" -> android:versionName="1.8"

and added Permission:

<uses-permission android:name="android.permission.VIBRATE" />

Why the new installation path and the new data? Anybody an idea whats happend?

Update Maybe proguard is the problem. ??? The new sharedPreferences have other end letters.

OLD: de.xxx.yyy.a.f.xml
NEW: de.xxx.yyy.a.h.xml

I get the name from the class.

SharedPreferences mPrefs = activity.getSharedPreferences(
                THECLASS.class.getName(), Activity.MODE_PRIVATE);
PiOsA
  • 135
  • 9
  • The package name changing is normal, but preferences shouldn't be cleared. You may be hitting some device/emulator bug. – Nikolay Elenkov Feb 06 '14 at 13:56
  • Thank you, but i tried on three different devices. The updates before doesn't clear the preferences. – PiOsA Feb 06 '14 at 14:01
  • 2
    How did you verify that the preferences are gone? Did you check the actual file on the device? – Nikolay Elenkov Feb 06 '14 at 14:03
  • The data is still on the device. But new pref is there too. OLD: de.xxx.yyy.a.f.xml and the new one have other end letters *.a.h.xml – PiOsA Feb 07 '14 at 09:06

1 Answers1

4

Never use a classname as key for your sharedPreferences.

Better use a constant String for sharedPreferences instead of the class name.

Proguard will obfuscate your classname and this could be changed if you add or modify something in your project. With proguard your classname is dynamic.

SharedPreferences mPrefs = activity.getSharedPreferences(
                YOURSTRING, Activity.MODE_PRIVATE);
NerdNeo
  • 319
  • 1
  • 6