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 andEnvironment.isExternalStorageEmulated()
returns true. Note that you should be managing the maximum space you will use for these anyway, just like withgetCacheDir()
.
看起来设备必须是 Android 4.2 及更高版本才能用于外部存储缓存。您可以让您的应用自行清理。参见 here用于检测您的应用何时将被卸载。
关于java - 保存在外部缓存中的文件不会在卸载时删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10674503/