为什么要在Android上使用getCacheDir() [英] Why to use getCacheDir() on Android

查看:1074
本文介绍了为什么要在Android上使用getCacheDir()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

机器人可以自动删除该文件CacheDir一旦系统变得内存不足。但该文档说,我们不应该靠制度清除该缓存,并因此写额外的code轮询和删除。

如果是这样的话,为什么要选择一项 getCacheDir() getFilesDir()?两者都是在存储器,后者提供了更多的功率到显影剂中的什么清理并当术语

谢谢!

解决方案
  

机器人可以自动删除CacheDir一次文件系统变得内存不足。

正确的。第三方应用程序也可以删除应用程序的缓存目录中的文件。而且,正如zapl注释,用户可以手动清除设置一个应用程序的高速缓存。

  

但该文档说,我们不应该靠制度清除该缓存,并因此写额外的code轮询和删除。

也是正确的。

  

如果是这样的话,为什么人应该选择getCacheDir()在getFileDir()?

由于操作系统,第三方应用程序和用户的可以的清除缓存。然而,仅仅因为那些东西的可以的清除缓存并不意味着他们自动的将会的清除缓存,所以你需要时不时地自己清理缓存。同样,虽然你母亲的可以的整理房间,所以一般如果你打扫你的房间你自己,如果你不想用扫帚击中一个好主意。

  

和后者提供了更多的权力,开发商在什么清理条款,当...

没有,没有。 getCacheDir()返回文件对象。 getFilesDir()返回文件对象。它们是在换算的当量功率到显影剂中的什么清理和术语时

Android may auto-delete the files in CacheDir once the system gets low on memory. But the docs say we should not rely on the system clearing this cache, and hence write additional code for polling and deleting.

If this is the case, why should one choose getCacheDir() over getFilesDir()? Both are in-memory, and the latter offers more power to the developer in terms of what to clean up and when.

Thanks!

解决方案

Android may auto-delete the files in CacheDir once the system gets low on memory.

Correct. Third party apps can also delete files from apps' cache directories. And, as zapl notes, the user can manually clear an app's cache from Settings.

But the docs say we should not rely on the system clearing this cache, and hence write additional code for polling and deleting.

Also correct.

If this is the case, why should one opt getCacheDir() over getFileDir() ?

Because the OS, third-party apps, and the user can clear the cache. However, just because those things can clear the cache does not mean that they automatically will clear the cache, and so you need to tidy up your cache from time to time yourself. Similarly, while your mother can clean your room, it is generally a good idea if you clean your room yourself, if you don't want to be hit with a broom.

and the latter offers more power to the developer in terms of what to clean up and when...

No, it does not. getCacheDir() returns a File object. getFilesDir() returns a File object. They are equivalent in terms of "power to the developer in terms of what to clean up and when".

这篇关于为什么要在Android上使用getCacheDir()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆