用户卸载应用程序时未删除 SharedPreferences
SharedPreferences not being removed on user uninstalling application
有人在 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);
}
}
现在这应该 return false
在新的卸载上但是在新安装上调试它我在应用程序启动时得到以下信息。
我也 运行 Proguard 如果这很重要,当 运行 设备在未启用 proguard 的 APK 上时它运行正常。 运行 proguard 在任何其他设备上运行正常。
由于 Nexus 6P 是 运行 Android M,我认为 Automatic Backups 是问题所在。
我想你可以使用 allowBackup 来阻止它。
检查这个答案:
在 android M 及以上版本中,他们将应用程序备份保存在 google 驱动程序中,您可以通过使用禁用它,
转到您的项目 manifest 文件 Application 部分下将 android:allowBackup="true"
设置为 false.and 你很高兴。
您可以添加到清单中:
android:fullBackupContent="false"
有人在 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);
}
}
现在这应该 return false
在新的卸载上但是在新安装上调试它我在应用程序启动时得到以下信息。
我也 运行 Proguard 如果这很重要,当 运行 设备在未启用 proguard 的 APK 上时它运行正常。 运行 proguard 在任何其他设备上运行正常。
由于 Nexus 6P 是 运行 Android M,我认为 Automatic Backups 是问题所在。
我想你可以使用 allowBackup 来阻止它。
检查这个答案:
在 android M 及以上版本中,他们将应用程序备份保存在 google 驱动程序中,您可以通过使用禁用它,
转到您的项目 manifest 文件 Application 部分下将 android:allowBackup="true"
设置为 false.and 你很高兴。
您可以添加到清单中:
android:fullBackupContent="false"