用户卸载应用程序时未删除SharedPreferences [英] SharedPreferences not being removed on user uninstalling application

查看:345
本文介绍了用户卸载应用程序时未删除SharedPreferences的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人在Nexus 6P设备上遇到此问题吗?我仅在Nexus 6P(运行Google Fi)上遇到此问题.

当我安装该应用程序时,SharedPreferences中有一个userIsLoggedIn的密钥.

此区块:

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);
    }
}

现在,这应该在新的卸载上返回false,但在全新安装上调试它,我在应用程序启动中获得了以下内容.

如果这很重要,我也会运行Proguard,在未启用Proguard的APK上运行设备时,它运行正常.在任何其他设备上运行proguard都可以正常运行.

解决方案

由于Nexus 6P运行的是Android M,我认为自动备份是问题所在.

我认为您可以使用 allowBackup 停止那个.

检查此答案: https://stackoverflow.com/a/32010582/336312

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.

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.

解决方案

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

这篇关于用户卸载应用程序时未删除SharedPreferences的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆