2

I've used LRU cache for caching bitmap images. I used typical code for implementing those, and it works fine on Ice Cream Sandwich.

However, the caching process doesn't work on Gingerbread.

Here is a my code:

import android.support.v4.util.LruCache;

(...)

public class ThumbnailDownloader<Token> extends HandlerThread {
    (...)

    private static final String TAG = "ThumbnailDownloader";
    private LruCache<String, Bitmap> mMemoryCache;

    (...)

    public void addBitmapToMemoryCache(String key, Bitmap bitmap) {
        if (getBitmapFromMemCache(key) == null) {
            Log.i(TAG, "(Before)Cache size: " + ((Integer)mMemoryCache.size()).toString());
            mMemoryCache.put(key, bitmap);
            Log.i(TAG, "(After)Cache size: " + ((Integer)mMemoryCache.size()).toString());
            Bitmap cached = mMemoryCache.get(key);
            if (cached == null) {
                Log.i(TAG, "Fail to cache!");
            } else {
                Log.i(TAG, "Cached item: " + (String)cached.toString());
            }
        }
    }

    (...)
}

This code works fine on Ice Cream Sandwich. For example, when the first caching occurred, the output is:

02-18 10:59:42.505: I/ThumbnailDownloader(2691): (Before)Cache size: 0
02-18 10:59:42.505: I/ThumbnailDownloader(2691): (After)Cache size: 77
02-18 10:59:42.505: I/ThumbnailDownloader(2691): Cached item: android.graphics.Bitmap@4298cc38

However, the result on Gingerbread was different: (caching size was not changed)

02-18 10:59:03.209: I/ThumbnailDownloader(13652): (Before)Cache size: 0
02-18 10:59:03.209: I/ThumbnailDownloader(13652): (After)Cache size: 0
02-18 10:59:03.209: I/ThumbnailDownloader(13652): Fail to cache!

This item was not cached.

I tried to extend caching memory size, but the result was not changed.

How to solve this problem?

lancif
  • 737
  • 1
  • 8
  • 17

0 Answers0