android - 如何让android删除SD卡上的缓存?

标签 android caching sd-card

我必须做什么,Android 才能使用 GUI 删除我在 sdcard 上的缓存文件?

我在 /sdcard/Android/data/my.package.name/cache 中保存了一些数据,但 Android 告诉我我的应用有 0B 缓存数据。这是错误的!

最佳答案

您永远不应该硬连接路径——例如,上面显示的路径对于大多数 Android 设备都是不正确的,因为 /sdcard 不是外部存储所在的位置。您应该对外部缓存使用 getExternalCacheDir(),对内部缓存使用 getCacheDir()

请记住,如文档所述:

There is no guarantee when these files will be deleted. Note: you should not rely on the system deleting these files for you; you should always have a reasonable maximum, such as 1 MB, for the amount of space you consume with cache files, and prune those files when exceeding that space.

(强调他们的)

关于android - 如何让android删除SD卡上的缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7791419/

相关文章:

java.lang.nullpointerexception 与 sqlite 数据库

android - file.mkdirs() 不工作

android - 应用关闭后在 Android 中存储 ArrayList

java - 延迟行动

asp.net - 启动时缓存表 ASP.NET MVC 应用程序

asp.net-mvc - ASP.NET MVC3 IIS7.5 : Cache-Control maxage is always 0 (not good for client-side caching)

c++ - Arduino逐行读取SD文件C++

android - 防止用户删除sdcard中的文件夹或文件

android - 圆形进度条未覆盖整个可用空间

caching - 索引和标签切换位置