在开发针对所有4.1以上版本的Android应用程序时,我发现卸载应用程序并重新安装它不会清除其数据。
该应用程序被设计成存储它在第一个屏幕中询问的详细信息。
在操作系统4.4.4版本卸载并重新安装后,app会提示用户填写数据,这是正常的。但是在6.0版本中,相同的安装/卸载顺序将带回最初输入的数据。
我试图通过访问/data/data/my package文件夹来确保数据库在卸载后已经消失,并且在卸载期间确实删除了该文件夹。
我试图通过访问设置页面删除该应用程序,通过Titanium Backup,结果是一样的。该设备是运行v6.0的Nexus 5。
这种奇怪行为的原因是什么?
这个答案总结了多个现有的答案,包括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 10,那么你必须把android:hasFragileUserData="true"在AndroidManifest.xml的应用程序标签
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:name=".MyApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:allowBackup="true"
android:hasFragileUserData="true">
.....
</application>
</manifest>
android:hasFragileUserData是一个新的清单设置(我猜)。“如果为真,则提示用户在卸载时保留应用程序的数据”。这似乎是被滥用的时机,但我可以看到它在某些应用程序中可能有用的地方。
见https://commonsware.com/blog/2019/06/06/random -思考- q -β- 4. - html
这个答案总结了多个现有的答案,包括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>的改变只影响未来应用备份的创建(或不创建);任何现有的应用程序备份数据将仍然存在并被使用,直到被覆盖或清除(参见上面的说明清除设备的数据)。