我有一個可滾動的地圖應用程序,它現在有一個巨大的位圖。它在啓動時加載得很好,但是當它丟失前景狀態並且用戶再次將它回退時,出現內存不足錯誤。在onPause中,它使用回收來刪除位圖,並將其標記爲空。 onResume會檢查map == null是否會再次加載位圖,儘管我回收了位圖,但程序崩潰了......以下是一些代碼。在加載/繪圖之前,首先檢查位圖貼圖的所有其他引用是否爲空。內存不足錯誤處理大型位圖和Android活動生命週期
的onPause
protected void onPause() {
super.onPause();
Log.e("sys","onPause was called");
if (map != null)
{
map.recycle();
map = null;
System.gc();
Log.e("sys","trashed the map");
}
}
我的onResume
protected void onResume(){
super.onResume();
Log.e("sys","onResume was called");
if (map == null)
map = BitmapFactory.decodeResource(getResources(),
R.drawable.lowresbusmap);
Log.e("sys","redrew the map");
}
你在調試器中收到此錯誤,或者真正的手機上? – EboMike 2010-07-24 23:14:01
真正的手機(摩托羅拉機器人) – jfisk 2010-07-25 17:12:27