page.title=Displaying Bitmaps Efficiently trainingnavtop=true startpage=true next.title=Loading Large Bitmaps Efficiently next.link=load-bitmap.html @jd:body

Dependencies and prerequisites

Try it out

Download the sample

BitmapFun.zip

This class covers some common techniques for processing and loading {@link android.graphics.Bitmap} objects in a way that keeps your user interface (UI) components responsive and avoids exceeding your application memory limit. If you're not careful, bitmaps can quickly consume your available memory budget leading to an application crash due to the dreaded exception:
{@code java.lang.OutofMemoryError: bitmap size exceeds VM budget}.

There are a number of reasons why loading bitmaps in your Android application is tricky:

Lessons

Loading Large Bitmaps Efficiently
This lesson walks you through decoding large bitmaps without exceeding the per application memory limit.
Processing Bitmaps Off the UI Thread
Bitmap processing (resizing, downloading from a remote source, etc.) should never take place on the main UI thread. This lesson walks you through processing bitmaps in a background thread using {@link android.os.AsyncTask} and explains how to handle concurrency issues.
Caching Bitmaps
This lesson walks you through using a memory and disk bitmap cache to improve the responsiveness and fluidity of your UI when loading multiple bitmaps.
Displaying Bitmaps in Your UI
This lesson brings everything together, showing you how to load multiple bitmaps into components like {@link android.support.v4.view.ViewPager} and {@link android.widget.GridView} using a background thread and bitmap cache.