0

i'm making an Android application, and i had some problem in report with "out of memory exception", after many search on the net, I found that android:background was loading background image in memory.

so i'll remove all my "android:background" declarations in my XML files, and replace it by :

    background = new BitmapDrawable(getResources(),ImageFactoring.decodeSampledBitmapFromResource(getResources(), R.drawable.catalogue_button_poeles_bois, mMaxButton_Cheminees.getLayoutParams().width, mMaxButton_Cheminees.getLayoutParams().height));
    mMaxButton_Cheminees.setBackgroundDrawable(background);

and before to do that, i'd want to know if "setBackgroundDrawable" is loading picture in memory or not ?

theMouk
  • 595
  • 1
  • 7
  • 21

1 Answers1

1

Of course, it does. All you see on display is stored im memory. After you set the background it is immediately loaded. Either while inflating from xml or when setting explicitly. Don't use images larger than needed as a resource. And try to avoid large HQ images where possible.

Yaroslav Mytkalyk
  • 16,950
  • 10
  • 72
  • 99
  • can it reduce trouble with "out of memory", if i load each image at a good scaling ? – theMouk Mar 19 '13 at 10:57
  • It is better that you pre-scale the image and put it in res folder. You can have differenct scales for different screen sizes or densities http://developer.android.com/guide/topics/resources/providing-resources.html – Yaroslav Mytkalyk Mar 19 '13 at 12:08