在Android开发中,当destroy带有webview的Activity时会出现如下报错:
public void onDestroy() {
super.onDestroy();
wv_show.removeAllViews();
wv_show.destroy();
}
在调用destroy的时候,webview任然依附在父组件中,因此需要先在父组件中将webview移除,然后在destroy;
public void onDestroy() {
super.onDestroy();
if (wv_show != null) {
final ViewGroup viewGroup = (ViewGroup) wv_show.getParent();
if (viewGroup != null) {
viewGroup.removeView(wv_show);
}
wv_show.removeAllViews();
wv_show.destroy();
}
}
本文详细介绍了在Android应用开发过程中,如何避免WebView组件导致的内存泄漏问题。通过正确的释放资源和从父视图中移除WebView,确保Activity销毁时不会出现错误。
945

被折叠的 条评论
为什么被折叠?



