アクティビティのOOMエラーに問題があります。2つのイメージビューと約5つまたは6つのボタンを使用するレイアウトがあります。現在、OOMエラーが発生しますが、これらの方法で改善が見られました。この方法を使用して、ホーム画面でレイアウトを設定します。
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);
}
次に、onPauseメソッドでこのメソッドを呼び出します。
private void recycleHomescreenImages() {
for (Bitmap bmap : bitmaps) {
bmap.recycle();
}
bitmaps = null;
}
これにより、ホーム画面アクティビティを終了する際のヒープ使用量が減少しますが、それだけでは不十分です。私が使用する他のビューはImageViewsではないため、setImageBitmap()メソッドを使用するのと同じ戦術を採用することはできません。ボタンの背景の収集を強制する方法についての提案はありますか?これが私のボタンの1つが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"/>
助けてくれてありがとう。