When implementing LruCache
, you should specify the cache size, and tell it how to calculate the size for each object (in this case, the object is bitmap).
You can use the following sample:
// uses 1/8th of the memory for the cache
final int cacheSize = (int) (Runtime.getRuntime().maxMemory() / 8L);
LruCache bitmapCache = new LruCache(cacheSize) {
protected int sizeOf(String key, Bitmap value) {
return value.getByteCount();
}}