93

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?

s3kt0r
  • 1,163
  • 1
  • 7
  • 16
  • You might be setting the values before clearing them. In this case you may need to upload your code so we can figure whats wrong with your app. – 0014 Feb 20 '16 at 00:06
  • 4
    My guess is that you did not opt out of auto-backup in your app, and you set up your device to automatically back up its data to Google. That data will automatically be restored on the next install of your app. – CommonsWare Feb 20 '16 at 00:11

3 Answers3

195

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.

Ely Dantas
  • 705
  • 11
  • 23
Mo1989
  • 2,374
  • 1
  • 15
  • 17
28

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

Manohar
  • 22,116
  • 9
  • 108
  • 144
0

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.

JoanaBrew
  • 11
  • 4