Sunday, July 24, 2011

[android-developers] Re: Listbox with ImageView and heapspace

Purge the queue that is filled by your background process.

List item views (and imageviews within your list item views) are recycled. Remember for which list-item (or image-view) the background-thread is loading a bitmap (you'll know this in the adapter's getView method). Later, as soon as the same image-view is re-used for another bitmap, look-up the loading of the bitmap that was previously to be assigned to the image-view and remove this bitmap from the cache. For good measure, call 'recycle()' on it. Then start load the new bitmap for the recycled image-view.

Instead of immediately purging unused bitmap, you may want to hold on to them a little longer so that your background doesn't need to re-load the same image over and over again. However, this will increase the size of your queue. You'll have to put a limit on the queue (never more than 'x' bitmaps in the queue).

Also be sure to load bitmaps that are at most slightly larger than your image-view (BitmapFactory.Options.inSampleSize > 1). Don't load full-sized bitmap if it's not absolutely necessary.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment