1

I am getting the infamous java.lang.OutOfMemoryError: bitmap size exceeds VM budget error. I have several XML layouts and a lot of the elements have images (button backgrounds, Linear layout backgrounds, etc.) After going through the questions posted, like Strange out of memory issue while loading an image to a Bitmap object and external allocation too large for this process and OutofMemoryError: bitmap size exceeds VM budget (Android) and Android: Error loading images: OutOfMemoryError: bitmap size exceeds VM budget I know I should use the BitMapFactory methods. But all my images are defined in my XML for example,

    <ImageView
        android:layout_width="80dp"
        android:layout_height="20dp"
        android:layout_marginBottom="3dp"
        android:src="@drawable/username" />

How do I go from defining the images in my XML to defining them programatically so that I can try playing around with BitMapFactory in hopes that it will eliminate my OOM exception?

Community
  • 1
  • 1
Nouran H
  • 1,992
  • 5
  • 18
  • 24
  • Just using `BitmapFactory` will not eliminate the problem on its own. You'll just get the same errors in different places. You need to stop for a minute and think whether you really do need so many images at the same time. Maybe you can show one image, then remove and recycle it before showing the next one. – Aleks G Jun 22 '12 at 17:05
  • @ Aleks G thank you for your prompt reply. I don't use that many images per Activity (usually <10). I tried to unbind my drawables as demonstrated in the second answer on this thread http://stackoverflow.com/questions/1147172/what-android-tools-and-methods-work-best-to-find-memory-resource-leaks but it didn't work. Could you please post code sample as to how I can load my images programatically (instead of in my XML layouts) and recycle them? Or any useful links. Thank you in advance. – Nouran H Jun 22 '12 at 17:33
  • Did you find out the solution? – Nam Vu Mar 12 '13 at 09:53

0 Answers0