简体   繁体   English

android在设备上加载和保存图像

[英]android loading and saving images on the device

I am building the application that will load list of news from the website. 我正在构建将从网站加载新闻列表的应用程序。 Each news/headline has an image. 每个新闻/标题都有一张图片。 I want to save/cash the images so user does not has to download them again. 我想保存/兑现图像,以便用户无需再次下载。

Q: In your opinion, what would be a better/more sufficient way: Loading images and saving them on the device or use the CacheManager? 问:在您看来,什么是更好/更充分的方式:加载图像并将其保存在设备上或使用CacheManager? At the moment I am using the first solution and everything works fine. 目前我正在使用第一个解决方案,一切正常。 However, the website has many categories and even more news per category therefore there are lot of images saved on the device. 但是,该网站每个类别有很多类别甚至更多新闻,因此设备上保存了大量图像。 Is it normal in this type of applications to save the images on the device? 在这种类型的应用程序中将图像保存在设备上是否正常?

Thanks for your help, marqs 谢谢你的帮助,marqs

I didn't find a reason to use CacheManager. 我没有找到使用CacheManager的理由。 I used getCacheDir and stored everything on file. 我使用了getCacheDir并将所有内容存储在文件中。 I have two levels of cache. 我有两级缓存。 First when I fetch it, I store in memory and disk. 首先,当我获取它时,我存储在内存和磁盘中。 When in memory gets bigger than 30 objects, I started clearing the memory to make some room for the new images coming. 当内存大于30个对象时,我开始清理内存,为新图像腾出空间。 However, I still keep the images around on disk and bring in to memory as needed. 但是,我仍然将图像保存在磁盘上并根据需要引入内存。 I found this to give me the smoothest scrolling. 我发现这给了我最顺畅的滚动。 After about an hour, I start expiring the image on disk too. 大约一个小时后,我也开始使磁盘上的映像到期。

I don't think you should save the images on the device, because of many reasons: 我不认为你应该将图像保存在设备上,原因有很多:

  1. Why wasting the device space on news images? 为什么要在新闻图片上浪费设备空间? All the user wants is to read the news and thats it. 所有用户想要的是阅读新闻,就是这样。 (In your case maybe open it later, but still - not forever) (在你的情况下可能稍后打开,但仍然 - 不是永远)
  2. You can save it on the device and make the app. 您可以将其保存在设备上并制作应用程序。 delete those files after lets say 24 hours.. 让我们说24小时后删除这些文件..
  3. The main issue is the privacy issue, when the user is deleting the cache files he thinks all the webs he visited has wiped from the device, but in this case they aren't.. 主要问题是隐私问题,当用户删除缓存文件时,他认为他访问过的所有网络都已从设备中擦除,但在这种情况下,它们不是......

Maybe you can just add a "Clean Cache" button in the app. 也许你可以在应用程序中添加一个“Clean Cache”按钮。 but after all I wrote I think using the Cache-manager is the best way - just because it was meant for those things exactly.. 但毕竟我写了我认为使用Cache-manager是最好的方法 - 只是因为它是为那些东西准确的...

:) :)

Rotem ROTEM

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM