So I got this background image for my activity. Its a 480×800 png.
It has a gradient in it, so there is danger of banding, that’s why I made it 99% opaque to force the best color mode.
On my device, and even on a HTC magic this is no problem.
However, on the default 1.6 emulator, I get out of memory errors. What to do?
The background is set in code with:
bgView.setImageResource(R.drawable.baby_pink_solid);
Setting the max VM heap to 192 and device ram size to 256 does not seem to be a solution.
Try accessing the Bitmap in code, and then set it via
setImageBitmap(). If you get an OOM when you are decoding the Bitmap in code, then this is why you are getting it fromsetImageResource().I have found that Bitmaps are a tricky thing to handle on Android, and you have to be careful when using them!
Also check out @Sadeshkumar Periyasamy’s answer, this is useful for decoding Bitmaps or larger sizes for devices which do not have as much power as todays devices.