Memory error related to large bitmap images and android activity life cycle

I have a scrollable app that currently has a huge bitmap. It loads normally at startup, but when it loses the foreground status and the user returns it again, receiving an error from memory. In onPause, it breaks the bitmap using recycle and marks it as null. OnResume checks if map == null and loads the bitmap again, which causes the program to crash, even though I am processing the bitmap ... Here are a few bits of code. All other links to the Bitmap map first check to see 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");
}
+5
1

:

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

All Articles