I'm having a problem with OOM errors in my activities. I have a layout which uses two imageviews and a about 5 or 6 buttons. Currently, I get an OOM error but noted improvement with these methods. I use this method to setup my layout in the homescreen:
private void createButtons()
{
bitmaps = new ArrayList<Bitmap>();
ImageView img = (ImageView)findViewById(R.id.homescreen_logo);
Bitmap bmp = (Bitmap)BitmapFactory.decodeResource(getResources(), R.drawable.homescreen_logo);
img.setImageBitmap(bmp);
bitmaps.add(bmp);
ImageView imge = (ImageView)findViewById(R.id.countdown_labels);
Bitmap bitmp = (Bitmap)BitmapFactory.decodeResource(getResources(), R.drawable.homescreen_countdown_text);
imge.setImageBitmap(bitmp);
bitmaps.add(bitmp);
}
then, in the onPause method I call this method:
private void recycleHomescreenImages() {
for (Bitmap bmap : bitmaps) {
bmap.recycle();
}
bitmaps = null;
}
While this does lower my heap usage upon exiting the homescreen activity, it is not enough. Since the other views I use are not ImageViews, I can't employ the same tactic of just using the setImageBitmap() method. Any suggestions on how I can also force the collection of backgrounds for a button? Here's what one of my buttons look like in xml.
<Button
android:id="@+id/1_button"
android:layout_width="294dp"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp"
android:background="@drawable/homescreen_button_1"
android:onClick="onClick1"/>
Thanks for any help.