开发者

android loading and saving images on the device

开发者 https://www.devze.com 2023-01-31 07:27 出处:网络
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.

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? 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


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..
  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. but after all I wrote I think using the Cache-manager is the best way - just because it was meant for those things exactly..

:)

Rotem


I didn't find a reason to use CacheManager. I used getCacheDir and stored everything on file. 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. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号