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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章