我在我的活動中遇到了OOM錯誤。我有一個使用兩個圖像瀏覽和大約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;
}
雖然這確實在退出主屏幕活性降低我堆的使用情況,那還不夠。由於我使用的其他視圖不是ImageView,因此我不能使用僅使用setImageBitmap()方法的相同策略。有關我如何還可以強制收集按鈕背景的建議?這是我的一個按鈕在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"/>
感謝您的任何幫助。
你是什麼意思加載懶惰? – user1132897 2012-07-30 15:30:10
看到這個線程:http://stackoverflow.com/questions/36274/what-is-lazy-loading – overbet13 2012-07-30 16:26:00