I've been researching this issue for the whole day. Here are key points:
adb install -r new.apk
with the new (updated, signed, versionCode incremented) APK)8 hours later
For test I changed SharedPrefs filename in new.apk
(SP2.xml) and upon updating, the old SharedPrefs file from old.apk
(SP.xml) got deleted! Here is adb shell output:
adb install old.apk
adb shell "su -c 'ls /data/data/com.pkg.name/shared_prefs'"
:
CRC.xml
adb install -r new.apk
adb shell "su -c 'ls /data/data/com.pkg.name/shared_prefs'"
:
CRC2.xml (CRC.xml missing!)
My SharedPreferences singleton class (init: SharedPrefs.init(getApplicationContext());
):
public final class SharedPrefs {
private static SharedPrefs sp;
private SharedPrefs() {
}
public static void init(Context context) {
if (sp == null)
sp = context.getSharedPreferences("CRC2", Context.MODE_PRIVATE);
}
public static void saveString(String name, String value) {
sp.edit().putString(name, value).apply();
}
public static String getString(String key, String defaultValue) {
sp.getString(key, defaultValue);
}
...
}
So basically I am loosing SharedPreferences and I have no clue why. Please help, any hint welcome!
If you changed a property in the application section of the manifest file, this error will occur and 90% of the time, the shared pref data will be reset. This is what I found from my test installing the signed apk on top of my play store app. Not sure what will happen if the app was installed from the play store as an update, but am pretty sure the data would be lost in that case as well.
EDIT- I republished the application and tested multiple times. This in fact is the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With