卸载时没有清除 SharedPreferences

好吧,这是一个奇怪的,我甚至认为是不可能的。

因此,自从我使用了 Nexus5X 之后,卸载应用程序时,SharedPreferences 并没有被清除。

我通过 Android Studio 安装这个应用程序并进行测试。然后卸载应用程序。然后通过 Android Studio 重新安装应用程序,所有 SharedPreferences 值仍然存在。

除了卸载之外,我还尝试过清除数据/缓存。

我在 Nexus 5X 上使用的是原装的 Android 6.0。我的设备没有被植入。我没有使用自定义 ROM。我的 Nexus4没有这个问题。

知道是什么引起的吗?

18435 次浏览

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.

Adding to Mo1989 answer , if android:allowBackup="false" clashes with any other library then use tools:replace="android:allowBackup" inside application tag of Androidmanifest.xml to fix the error

if it's only because of testing and you are testing you also run

adb shell pm clear [package name]

which will clear the data.