在开发针对所有4.1以上版本的Android应用程序时,我发现卸载应用程序并重新安装它不会清除其数据。
该应用程序被设计成存储它在第一个屏幕中询问的详细信息。
在操作系统4.4.4版本卸载并重新安装后,app会提示用户填写数据,这是正常的。但是在6.0版本中,相同的安装/卸载顺序将带回最初输入的数据。
我试图通过访问/data/data/my package文件夹来确保数据库在卸载后已经消失,并且在卸载期间确实删除了该文件夹。
我试图通过访问设置页面删除该应用程序,通过Titanium Backup,结果是一样的。该设备是运行v6.0的Nexus 5。
这种奇怪行为的原因是什么?
我最近需要利用这些功能,我能够找到文档,经过广泛的测试,我能够推断出以下内容:
Android:allowbackup -将备份它所在设备上的本地应用数据。
Android:fullBackupContent -与谷歌的备份恢复api一起使用,可以通过一个xml文件来控制,以指定备份的内容,以及一个BackupManager类,您可以实现对过程的进一步控制。
However the documentation states, and I have confirmed with testing, that a restore will only occur either when the device is restored and the restore app data process is triggered. OR it will also restore when the app is sideloaded through adb, which is what we do when we run the app for testing or debug on our devices through Android Studio. Note that if you set android:allowbackup but do not configure android:fullBackupContent with a Google api code then the apps data only gets stored locally, whereas if you configured it properly then if your app was backed up and you get a new device the apps data was stored on the cloud so it can be restored on a new device.
这个答案总结了多个现有的答案,包括Android 12推出的最新细节,并包括清除设备上现有应用备份数据的说明。
有关更多信息,请参见
https://developer.android.com/guide/topics/data/autobackup#EnablingAutoBackup
https://developer.android.com/about/versions/12/behavior-changes-12#backup-restore
https://developer.android.com/guide/topics/manifest/application-element
http://android-doc.github.io/preview/backup/index.html(用于清除存储在设备谷歌驱动器中的现有应用程序备份数据:设置>备份>切换谷歌一次备份关闭,然后再次恢复,然后重试卸载/重新安装)
作为旁注,其他一些答案建议android:fullBackupContent="false",但这似乎不再正确,因为这目前意味着指定一个特定格式的xml文件,而不是真/假。
<application>的这些属性允许禁用或配置Android自动备份功能的细节。
<application
tools:replace="android:label, android:icon, android:allowBackup, '...any other attribute you want to override with a value you set in this file for in case dependencies set them to other values...'"
'...your other attributes set here like android:label and android:icon...'
android:allowBackup="false" '...default is true, and setting this false prevents data backups of any kind (except device to device transfers if your app targets Android 11 (API 30) or higher)...'
android:fullBackupContent="@xml/backup_rules_android_11_and_below" '...optional, for Android 11 and below, referring to a file res/xml/backup_rules_android_11_and_below.xml you need to create...'
android:dataExtractionRules="@xml/backup_rules_android_12_and_above" '...optional, for Android 12 and above (fullBackupContent still needed along with this, assuming you support Android 11 and below), referring to a file res/xml/backup_rules_android_12_and_above.xml you need to create, with a slightly different required xml format...'
android:fullBackupOnly="false" '...optional, and default is false, but if set to true this field description says it enables auto backup on Android 6 (API 23) devices or higher (I am not sure how this matters compared to the more broadly reaching allowBackup)...'
android:hasFragileUserData="false" '...optional, and default is false, but if set to true this field description says it gives the user an option when they uninstall the app whether or not to backup their app data...'
>
'...contents of application element...'
</application>
<application>的改变只影响未来应用备份的创建(或不创建);任何现有的应用程序备份数据将仍然存在并被使用,直到被覆盖或清除(参见上面的说明清除设备的数据)。
我最近需要利用这些功能,我能够找到文档,经过广泛的测试,我能够推断出以下内容:
Android:allowbackup -将备份它所在设备上的本地应用数据。
Android:fullBackupContent -与谷歌的备份恢复api一起使用,可以通过一个xml文件来控制,以指定备份的内容,以及一个BackupManager类,您可以实现对过程的进一步控制。
However the documentation states, and I have confirmed with testing, that a restore will only occur either when the device is restored and the restore app data process is triggered. OR it will also restore when the app is sideloaded through adb, which is what we do when we run the app for testing or debug on our devices through Android Studio. Note that if you set android:allowbackup but do not configure android:fullBackupContent with a Google api code then the apps data only gets stored locally, whereas if you configured it properly then if your app was backed up and you get a new device the apps data was stored on the cloud so it can be restored on a new device.