I dealt with that a while ago. Experimented with performance too. Here's what I got.
This answer is beyond lazy loading of images because it deals with performance.
First of all: Forget about SoftReferences
on android. Very bad for caching because of misbehavior (released to soon). I ended up using LruCache (source for API < 12) with a fixed byte size for the cache.
When loading images through network you want to persist the loaded images (in private app data folder or SD card). Otherwise the user is forced to load (unnecessary) data on every app startup. Here's the routine:
- image is requested
- check for image in memory cache (jump to 6. if available)
- is persisted locally (jump to 5. if so)
- load from network and persist
- load bitmap into cache
- load bitmap from cache into view
Now some words for performance. If every list item has another image and they have a fixed size (e.g. 40 x 40 dip
) you would waste cache memory when loading full images (e.g. 800 x 600 px
) and your device would have to calculate a lot for scaling.
First solution is to prescale the bitmap on step 5.
before loading image into cache. You'll get the best performance when you persist the scaled image and load it next time.
You can find an example in my CoverCache helper (CD covers - but can be used for any kind of image data). It deals with persisting, scaling and caching images at the same time.