This is a runtime error that happens when you request a large amount of memory on the heap. This is common when loading a Bitmap into an ImageView.
You have some options:
- Use a large application heap
Add the “largeHeap” option to the application tag in your AndroidManifest.xml. This will make more memory available to your app but will likely not fix the root issue.
<application largeHeap="true" ... >
- Recycle your bitmaps
After loading a bitmap, be sure to recycle it and free up memory:
if (bitmap != null && !bitmap.isRecycled()) bitmap.recycle();
- Load sampled bitmaps into memory
Avoid loading the entire bitmap into memory at once by sampling a reduced size, using BitmapOptions and inSampleSize.
See Android documentation for example
Found a mistake? Have a question or improvement idea? Let me know.
Table Of Contents