英文:
Files in internal storage "getFilesDir()" are not being deleted when app is uninstalled
问题
标题基本上已经表达了一切。
我使用从 getFilesDir()
获取的路径在内部存储中创建了文件,认为这些文件在应用被卸载时应该被删除。但实际上它们并没有被删除。
如果我想要删除这些数据,我必须在我的手机应用程序设置中手动进行,或者在Android Studio中使用设备文件浏览器手动删除这些文件。这并不理想。
有人可以提供帮助吗?
英文:
Title pretty much says it all.
I created files in internal storage with the path from getFilesDir()
with the idea that they should be deleted when the app gets uninstalled. But they are not being deleted at all.
If I want to delete the data I have to do it manually in my phones applications settings, or manually delete the files out with the device file explorer in Android Studio. This is not ideal.
Can anyone help?
答案1
得分: 2
在`<application>`中有一个名为`android:allowBackup`的属性,用于控制操作系统是否可以自动备份应用程序的数据。如果将此属性设置为`true`并且重新安装应用程序,则会恢复其数据的备份。在开发过程中,这可能会带来麻烦。而且,在生产环境中,无论是您还是用户都无法对备份过程进行太多控制。
如果您希望禁用此功能,针对`debug`构建或所有构建,在适当版本的清单中的`<application>`上设置`android:allowBackup="false"`(例如,针对所有构建设置`src/main/`,针对`debug`构建设置`src/debug/`)。
英文:
There is an android:allowBackup
attribute available for <application>
that controls whether the app's data can be backed up automatically by the OS. If this attribute is set to true
and the app is reinstalled, a backup of its data is restored. During development, this can be a pain. And, in production, neither you nor the users have much control over the backup process.
If you wish to disable this — for debug
builds or all builds — set android:allowBackup="false"
on <application>
in the appropriate edition of the manifest (e.g., src/main/
for all builds, src/debug/
for debug
builds).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论