s3kt0r
s3kt0r

Reputation: 1243

SharedPreferences are not being cleared when I uninstall

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?

Upvotes: 101

Views: 25404

Answers (3)

JoanaBrew
JoanaBrew

Reputation: 31

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.

Upvotes: 2

Mo1989
Mo1989

Reputation: 2494

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.

Upvotes: 207

Manohar
Manohar

Reputation: 23384

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

Upvotes: 29

Related Questions