How to fix OutOfMemoryError exception in android?

50 Views Asked by At

I am new to android development in fact. I have an android app dealing with large length of list and each list item has bitmap thumbnail. The app load the entire database so it is clearly not efficient. But for now I can't code it again efficiently because it will spend much time and also can't use try and catch because I don't know where this exception will occur. I just want to know another simple solution such as android:largeHeap="true", dexOption in app.gradle or org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError in gradle.property.

I tried them but nothing is improved.

2

There are 2 best solutions below

0
Lazy Ninja On

OutOfMemoryError with large bitmaps is a known issue in Android.

You need to handle it in your source code. Tweaking the Manifest file settings is not the solution.

Here an example how to deal with large bitmaps.

https://developer.android.com/topic/performance/graphics/load-bitmap

Libraries like Picasso can make your job more easier.

1
Bartek Pacia On

Use library like Picasso or Glide.