How to destroy/release resources used in 1 activity/layout?

杀马特。学长 韩版系。学妹 提交于 2019-12-02 08:37:41

YOu can release resources by using the following code. This should be called in onDestroy() of u=your activity.

private void unbindDrawables(View view) {
    if (view.getBackground() != null) {
        view.getBackground().setCallback(null);
    }
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            unbindDrawables(((ViewGroup) view).getChildAt(i));
        }
        ((ViewGroup) view).removeAllViews();
        view.setBackgroundResource(0);
    }
}

More over to destroy activity you should call finish() after calling next activity.

You should use OnStop() callback to release the resources that causing the memory leak. You should also use onStop() to perform relatively CPU-intensive shutdown operations.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!