首页 > 代码库 > Error: WebView.destroy() called while still attached 解决方法

Error: WebView.destroy() called while still attached 解决方法

一般是在 Activity 的 OnDestroy 中处理 webView,代码如下:

    public void onDestroy() {        super.onDestroy();        if (webView != null)            webView.destroy();    }

但会出现错误:Error: WebView.destroy() called while still attached

解决方法如下:

    public void onDestroy() {        if (webView != null) {            ViewGroup parent = (ViewGroup) webView.getParent();            if (parent != null) {                parent.removeView(webView);            }            webView.removeAllViews();            webView.destroy();        }        super.onDestroy();    }}

  

Error: WebView.destroy() called while still attached 解决方法