I am building an “Image Gallery” app that would fetch about 50 – 60 HD images from a site. The site will update the image list thrice a week and so new images will have to be fetched and old images discarded when the app is launched the next time.
What’s the best way to cache these images and lazy load them without running
into OutOfMemory and SoftReference issues? Lazy loading would be needed because each Image thumbnail has a caption and freezing the thumbnail UI till the image loads is not a good idea.
Also, for lazy loading images – is it really a good design to spawn a thread for each thumbnail and implement a queue to handle the threads? Is there an easier way?
Please help!
Thanks for reading!
You can have a loot at PicHelper from Zwitscher source for a class that does the fetching and storing on the local file system, as well as reading Bitmaps from those files again.
Within the main code you would start an
AsyncTaskto fetch the images (in itsdoInBackground()method. To prevent OOME I’d put the list of images to fetch in a “queue” and fetch them in serial, rather than parallel. Many handsets out there only have 48MB of heap or less.