java - 保存在外部缓存中的文件不会在卸载时删除

标签 java android

Here据说保存在 getExternalCacheDir() 上的文件将在卸载时被删除。

我已将下载的文件放在那里。 3 台设备一切正常。 但是对于一台搭载 Android 4.0 的 Samsung Galaxy S2,这些文件不会被删除。 这可能是什么原因?

最佳答案

查看 getExternalCacheDir()文档:

The platform does not always monitor the space available in external storage, and thus may not automatically delete these files. Currently the only time files here will be deleted by the platform is when running on JELLY_BEAN_MR1 or later and Environment.isExternalStorageEmulated() returns true. Note that you should be managing the maximum space you will use for these anyway, just like with getCacheDir().

看起来设备必须是 Android 4.2 及更高版本才能用于外部存储缓存。您可以让您的应用自行清理。参见 here用于检测您的应用何时将被卸载。

关于java - 保存在外部缓存中的文件不会在卸载时删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10674503/

相关文章:

android - 如何将 listView 标题添加为自定义布局

android - 更新 ADT 后无法从 AVD(模拟器)中的键盘(硬件)输入

java - FindViewByID 在 Fragment Navigation Drawer 上返回 null

android - 添加新插件后 cordova_plugins.js 未更新

java - 从 Azure Java SDK 列出我的 Azure 权限

java - 通过 SOAP API 将报告部署到 JasperServer

java - 无法部署 War 文件 : error in opening zip file

android - 使用向上按钮在 Activity 之间导航

java - 我的对象值不会保存。显示空

java - Apache Camel 和 MQTT : How to use simple language for e. g。主题?