Out Of Memory Exception In Textview.setbackground Resource In Android
I am trying to place an image as background in my TextView. I want the image to get changed by pressing a button. At the first image gets loaded but when I try for next time it say
Solution 1:
image memory usage is based on multiple things:
- resolution of the image.
- where the image file is located (the density qualifier of the drawable folder) compared to on which screen density the app is running on.
- which bitmap format you used .
- whether or not the image is 9-patch image.
so , for example, if you have a 100x100 image, and the file is in "drawable-mdpi" yet it runs on an xhdpi device , and the bitmap format is the default one, and it's not a 9-patch image, the bitmap would take:
100*100 * 4 *4 = 160,000 bytes.
the 100*100 is because of the number of pixels for width and height.
the first 4 is because on the default bitmap format, each pixel takes 4 bytes.
the second 4 is because the density is 2 times larger in both width and height (2*2=4).
so, if this is the only code you show, i think you use too much memory because of your images.
one thing that you could do is to downsample them.
Post a Comment for "Out Of Memory Exception In Textview.setbackground Resource In Android"