Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharedPreferences are not being cleared when I uninstall

Tags:

android

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?

like image 537
s3kt0r Avatar asked Feb 19 '16 23:02

s3kt0r


People also ask

Are shared preferences deleted when app is deleted?

The old shared preference value are cleared and totally wiped out after clearing the data app and uninstalling it, so the SharedPreference should be empty in the fresh start.

Where are SharedPreferences stored in Android?

Android Shared Preferences Overview Android stores Shared Preferences settings as XML file in shared_prefs folder under DATA/data/{application package} directory. The DATA folder can be obtained by calling Environment.

Are SharedPreferences persistent?

Android's built-in SharedPreferences storage mechanism allows us to store information that persists throughout the entire app.


1 Answers

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.

like image 98
Mo1989 Avatar answered Sep 20 '22 06:09

Mo1989