androidbitmapandroid-bitmapandroid-lru-cache

LruCache returning wrong bitmaps for specified key


I am very new to Android development.

I am running into issues getting the correct bitmap from my LruBitmapCache. I use the UUID to generate a unique Id, I don't use a URL because I am generating the bitmap on a canvas. (I'm copying getDrawingCache() from my view to a new bitmap (using copy) then storing the copy into the cache).

For some reason after I store a bitmap, when I access it, it ends up being a bitmap for another id ... this happens sometimes. Any ideas?

I use a currentIndex to track which position I am at in the cachedKeys Array (I want to sequentially save and navigate through the bitamp on a canvas). I think I'm updating the entry in the cache wrong...


Solution

  • A fellow developer assisted. I was doing mDrawingView.restartDrawingCache(); incorrectly and in the wrong order.

    It should have been:

    <drawing view>.setDrawingCacheEnabled(true);
    Bitmap mmap= <drawing view>.getDrawingCache();
    Bitmap copy = mmap.copy(mmap.getConfig(), false);
    <drawing view>.setDrawingCacheEnabled(false);
    

    Cheers, maybe this will help someone out :)