0

Context:

I have a main activity holding 6 tabs, each tabs holds a gridview with 30+ images, and around 8 images a shown at any moment (each gridview is scollable).

With these many images I implemented a simple caching system, that is to only cache the latest 25 of them, if new image is needed to display and is not in the cache, I will decode that image from /data/date directory and overwrite the oldest entry in the cache. And before overwriting the oldest entry, I will call Bitmap.recycle() on that.

Problem:

At some point, after displying more than 25 images, old images will start to be recycled. if I were to now navigate back to one of the tab where their Image is no longer in the cache, the GetView method will take care to load the picture again. The Issue is other than the first Item in the Gridview will be calling GetView, rest of the image will never get call, and the Gridview will attempt to display a cached image where it has been recycled already.

Any Suggestion? either to force get view or a smart way to cache image in this scenario?

Much Appreciated

Thanks

bc1118
  • 1

1 Answers1

0

I kind of solved this by creating my own ImageView extending the Android ImageView. Then Overrided the onDraw(Canvas canvas) method and added logic to reload cache if cache is gone.

looks Hacky... but worked as wanted. really wish i cna do better than that if there is someone who can teach me. Thanks a ton!!

bc1118
  • 1