Question

I am using some png images for the backgrounds of activities in my application. These png files are mostly very small sized images. For example, I am using one with the size of 768x1024 which is actually 29.6KB on disk. When I run the application on my Samsung Note 1, I realized that the image actually consumes approx. 3MB of memory. So, Android seems to decompress the PNG file into a full ARGB bitmap (768x1024x4 bytes). I thought that this may be the result of the need of Android to resample/resize the image and placed the PNG file into the drawable-nodpi folder but this resulted in the same amount of memory consumption.

So, what should I do in this case, can I prevent this decompression behavior somehow? I have to put many different images for numerous activities in this project, so it seems that at a point this will cause out of memory errors. I am a beginner in Android and I don't know exactly how the system handles image resources, so I may miss something here.

Was it helpful?

Solution

Try adding these 2 lines to the in to the application tag in the manifest

android:hardwareAccelerated="false"
android:largeHeap="true" 

But these are not recommended if you are building a memory efficient App, But this really works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top