views:

98

answers:

1

I have a scrollable map app which for now has a huge bitmap. It loads fine on startup, but when it looses foreground status and the user brings it backs again im getting an out of memory error. In onPause it trashes the bitmap using recycle, and marks it as null. The onResume checks to see if map==null and will load the bitmap back again, which is crashing the program despite me recycling the bitmap...Here are some bits of code. All of the other references to Bitmap map first check if it is null before loading/drawing.

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");
}
}

my 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");
}
A: 

Try it this way:

protected void onResume(){
    super.onResume();
    if (map == null){
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inTempStorage = new byte[16*1024];

        map = BitmapFactory.decodeResource(getResources(),
                        R.drawable.lowresbusmap, options);
    }
}
Cristian
no luck, this image is actually meant for faster phones. The slower ones like the G1 will use a smaller bitmap. In that case would i change 16*1024 to 24*1024? Unfortunately that code is still giving me the same error.
Evan Kimia