Once in a while i get the error message “Bitmap size exceeds VM budget”. It happens when i open 20 activities one after another where each of the activities holds a 500×300 PNG picture. I didn’t have the problem when i implemented the pictures in my XML layouts with android:background=”@drawable/xxxxxxxx”.
The error first occured when i implemented the pictures in my Java code.
<ImageView
android:id="@+id/ImVpic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
ImageView pic;
pic = (ImageView)findViewById(R.id.ImVpic);
pic.setImageResource(R.drawable.picture);
How can i get rid of that error? What is missing in my code? I mean it actually works, but from time to time it throws that error which is really annoying.
This is very common question you see on SO. It seems while loading the image, available memory is low. Make sure you are not keeping for long references for images, which allows dalvik to reclaim the memory from unused images (or) objects.