在应用被卸载时,存储在内部存储中的文件“getFilesDir()”不会被删除。

huangapple go评论115阅读模式
英文:

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 &lt;application&gt; 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 &mdash; for debug builds or all builds &mdash; set android:allowBackup=&quot;false&quot; on &lt;application&gt; in the appropriate edition of the manifest (e.g., src/main/ for all builds, src/debug/ for debug builds).

huangapple
  • 本文由 发表于 2020年9月2日 02:31:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/63693499.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定