Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

Handling bitmaps

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

  • Bitmaps can very easily exhaust an app's memory budget. For example, the camera on the Pixel phone takes photos of up to 4048x3036 pixels (12 megapixels). If the bitmap configuration used is ARGB_8888, the default for Android 2.3 (API level 9) and higher, loading a single photo into memory takes about 48MB of memory (4048*3036*4 bytes). Such a large memory demand can immediately use up all the memory available to the app.
  • Loading bitmaps on the UI thread can degrade your app's performance, causing slow responsiveness or even ANR messages. It is therefore important to manage threading appropriately when working with bitmaps.
  • If your app is loading multiple bitmaps into memory, you need to skillfully manage memory and disk caching. Otherwise, the responsiveness and fluidity of your app's UI may suffer.

For most cases, we recommend that you use the Glide library to fetch, decode, and display bitmaps in your app. Glide abstracts out most of the complexity in handling these and other tasks related to working with bitmaps and other images on Android. For information about using and downloading Glide, visit the Glide repository on GitHub.

You can also opt to work directly with the lower-level APIs built into the Android framework. For more information on doing so, refer to Loading Large Bitmaps Efficiently, Caching Bitmaps, and Managing Bitmap Memory.

More resources