Issue
Okay, so I have this really weird problem and I will explain it with an example.
Lets say I have 2 activities: ActivityOne, ActivityTwo. When pressing a button in ActivityOne it opens ActivityTwo (intent)
I have 2 background images in @drawables: onebg (size=31k), twobg (size=30k)
onebg is the background in ActivityOne. When trying to make twobg the background of ActivityTwo, it crashes with the Out of Memory error.
However, when setting onebg as the background for both ActivityOne and ActivityTwo, it works. Haven't tried setting twobg for both of them but I guess it will most likely work.
Both onebg and twobg are made by me in photoshop, they are the same type and everything, just different size because of different text on it.
Solution
I think you didn't understand the heap allocation of bitmaps correctly.
The size which each bitmap allocate in heap is not determined by its size !!! it's determined by its dimension !
Lets have an example:
you have a bitmap with 30kb size and dimension of 1000*500 pixel. the amount of memory is determined this way:
1000 * 500 * 4 (its because each pixel should contain ARGB informations)
So on devices with low heap you would have problem with such image sizes.
Also pay attention to @Drilon hint. You also should pay attention to Memory leak too.
Fore more information please refer to this link from google
Loading Large Bitmaps Efficiently
Answered By - Omid Heshmatinia
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.