Memory and Activities :: OutOfMemory

前端 未结 3 2150
一生所求
一生所求 2020-12-19 11:35

SETUP :

I have this app which has 4 activities in a linear path, really simple navigation : A -> B -> C -> D

All the activities share the

3条回答
  •  攒了一身酷
    2020-12-19 11:46

    You need to explicitly recycle Bitmap used as background when you destroying your activity. Code will be like this:

    @Override
    protected void onDestroy () {
        Drawable drawable = getView().getBackground();
        if (drawable instanceof BitmapDrawable) {
            ((BitmapDrawable)drawable).getBitmap().recycle();
        }
        drawable.setCallback(null);
        getView().setBackgroundDrawable(null);
        super.onDestroy();
    }
    

    Maybe you need to free resources recursively for nested views, but it depends on your layout structure. This is general case

提交回复
热议问题