Resource/Code path changing for pkg on Android App update

android, sharedpreferences

Solution

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);

Problem

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); ```

Original source