Resource/Code path changing for pkg on Android App update

本秂侑毒 提交于 2019-12-21 17:52:39

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/21604119/resource-code-path-changing-for-pkg-on-android-app-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!