当我在 Android 上删除应用程序时如何删除 SharedPreferences 6

How to remove SharedPreferences when I remove app on Android 6

当我使用标准删除方法(例如拖放)从设备上删除应用程序时,我的 SharedPreferences 无法清除。

为什么?

如何清洁我的 SharedPreferences

P.S。如果我在 Setting 手动 SharedPreferences 清除数据,但这对我来说不是解决方案。

How to clean my SharedPreferences?

您遇到的是 allowBackup 的默认行为,默认情况下是 true。来自文档:

Whether to allow the application to participate in the backup and restore infrastructure. If this attribute is set to false, no backup or restore of the application will ever be performed, even by a full-system backup that would otherwise cause all application data to be saved via adb. The default value of this attribute is true.

如果您想禁用它,请将 allowBackup="false" 添加到 AndroidManifest 上的应用程序标签中。这样 SharedPreferences 就不会恢复