WebView.destroy()报错called while still attached

在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基础)