SharedPreferences are not being cleared when I uninstall

Android

Android Problem Overview


OK, this is a strange one that I didn't think was even possible.

So, ever since I've been using a Nexus 5X, the SharedPreferences are not getting wiped when I uninstall my app.

I install the app through Android Studio and test things. I then uninstall the app. I then resintall the app through Android Studio and all the SharedPreferences values are still there.

I've tried clearing the data/cache in addition to uninstalling. The SharedPreferences are persistent through all those attempts.

I am using stock Android 6.0 on a Nexus 5X. My device is not rooted. I am not using a custom ROM. I do not have this issue with my Nexus 4.

Any ideas what might be causing this?

Android Solutions


Solution 1 - Android

This is a new marshmallow feature.

Add android:allowBackup="false" tag inside your <application> object in your app manifest to disable this behaviour.

If android:allowBackup tag clashes with any other library you are using, you should add tools:replace="android:allowBackup" also.

Solution 2 - Android

Adding to Mo1989 answer , if android:allowBackup="false" clashes with any other library then use tools:replace="android:allowBackup" inside application tag of Androidmanifest.xml to fix the error

Solution 3 - Android

if it's only because of testing and you are testing you also run

adb shell pm clear [package name] 

which will clear the data.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questions3kt0rView Question on Stackoverflow
Solution 1 - AndroidMo1989View Answer on Stackoverflow
Solution 2 - AndroidManoharView Answer on Stackoverflow
Solution 3 - AndroidJoanaBrewView Answer on Stackoverflow