Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharedPreferences not being removed on user uninstalling application

Has anyone encountered this issue on a Nexus 6P device? I am only getting this issue on a Nexus 6P (running Google Fi).

When I install the app there is a key for userIsLoggedIn inside SharedPreferences.

This block:

boolean userIsLoggedIn  = SharedPrefs.userIsLoggedIn(this);  // Then in another class...   public static boolean userIsLoggedIn(Context context) {     // For users updating apps, if the previous key-value is a string, convert it to boolean     try {         return context.getSharedPreferences(LOGIN_FILE, Context.MODE_PRIVATE)                 .getBoolean(USER_LOGGED_IN, false);     } catch (ClassCastException e) {         Logger.e(TAG, e.getMessage());         context.getSharedPreferences(LOGIN, Context.MODE_PRIVATE)                 .edit()                 .putBoolean(USER_LOGGED_IN, false)                 .commit();         return context.getSharedPreferences(LOGIN, Context.MODE_PRIVATE)                 .getBoolean(USER_LOGGED_IN, false);     } } 

Now this should return false on a new uninstall but debugging this on a fresh install I get the following on App Startup.

enter image description here

I also running Proguard if that matters, when running the device on a non-proguard enabled APK it runs ok. Running proguard on any other devices runs fine.

like image 271
AndyRoid Avatar asked Jan 27 '16 05:01

AndyRoid


People also ask

Does SharedPreferences persist after uninstall?

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. Actual results: I see that the old shared preference values are still loaded.

Are SharedPreferences persistent?

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

Are shared preferences deleted when app is deleted?

All we think is that the data was somewhere in shared preference and it was not deleted when we uninstalled the application. But that is simply not the case. The shared preference is definitely deleted when the application is uninstalled.


1 Answers

Since Nexus 6P is running Android M, I think Automatic Backups is the issue.

I think You can use allowBackup to stop that.

Check this answer: https://stackoverflow.com/a/32010582/336312

like image 87
code2be Avatar answered Sep 19 '22 10:09

code2be