Android M 奇怪的共享首选项问题

Android M weird shared preferences issue

在我的 Nexus 5 运行 Android M Developer Preview 2 上,当 uninstalling/reinstalling 一个应用程序时,设备正在检索我很久以前存储的共享首选项,例如布尔值 isFirstLaunch.

清除这些的唯一方法是从设备设置中手动进行。

AndroidM 上的共享首选项行为是否有任何变化?我找不到与此相关的任何文档。

或者 Android M Preview 2 ROM 有一个错误...

那是因为 Android M 将具有 Automatic Backups (old link).

摘录:

The automatic backup feature preserves the data your app creates on a user device by uploading it to the user’s Google Drive account and encrypting it. There is no charge to you or the user for data storage and the saved data does not count towards the user's personal Drive quota. During the M Preview period, users can store up to 25MB per Android app.

打开设置 -> 备份和重置 -> 自动恢复 -> 关闭 如果打开则应用程序缓存和数据库将被恢复。

上面已经回答了这个问题,却没有提到避免卸载应用后自动备份的实际解决方案。

根据官方的说法,doc 说要避免自动备份需要在应用程序标签下的清单文件中执行 <application android:allowBackup="false">。:

Enabling and disabling backup Apps that target Android 6.0 (API level 23) or higher automatically participate in Auto Backup because of the android:allowBackup attribute defaults to true. To avoid any confusion, you should explicitly set the attribute in your manifest as follows:

<manifest ... >
    ...
    <application android:allowBackup="false" ... >
        ...
    </application>
</manifest>

You might want to disable backups by setting this to false if your app can recreate its state through some other mechanism or when your app deals with sensitive information that should not be backed up