SharedPreferences not being removed on user uninstalling application
Asked Answered
B

3

58

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.

Blurt answered 27/1, 2016 at 5:15 Comment(3)
Have you checked with any other devices? Code seems fine.Ulster
I think login is true somewhere in code because shared preference dont behave like that so please check that first.Boisvert
That is definitely not the issue, this piece of code is run first. Have confirmed on 8 other devices.Blurt
D
96

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://mcmap.net/q/331612/-android-m-weird-shared-preferences-issue

Drama answered 27/1, 2016 at 5:26 Comment(0)
E
21

In android M and above versions they keep application backups in google driver, you can disable this by using, go to your project manifest file under Application section set android:allowBackup="true" to false.and you are good to go.

Evania answered 3/10, 2017 at 4:13 Comment(0)
D
18

you can add to your manifest:

        android:fullBackupContent="false"
Duplessis answered 16/4, 2018 at 13:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.