Wednesday, 14 August 2013

When to recycle bitmap in android project?

When to recycle bitmap in android project?

I have successfully implemented lazy loading of list images and list items
in Android listview. I am using Android 4.0+ and Java 7.
The algorithm i followed is:
List data(including image URL) is downloaded from internet as and when
user scrolls the list.
When scroll state is idle, list images are loaded.
In the background thread, images are first checked for in the cache. If
not present in cache, they are downloaded and stored into the cache.
Lastly image is set to imageview in the listview and adapter is notified.
The only problem is I am not clear about when to recycle bitmaps. I tried
using bitmap.recyle() at many places but I got the following error:
java.lang.IllegalArgumentException: Cannot draw recycled bitmap
It is not possible to add that vast code over here. Also there are some
privacy issues. Can someone please help me about this?

No comments:

Post a Comment