webview报错

WebView.destroy() called while WebView is still attached to window.

解决方法:

现在总结下这个问题的解决办法。先大概解释下这个错误,这个错误从字面意思来说是当你结束webview的时候,Webview还依附在父控件下,使用解决这个问题

就是在WebView.destroy()前要解除他们之间的依附关系。一般会碰上这个问题应该是这样对webview进行了操作:
protected void onDestroy()
{
    if (adView != null)
    {
        adView.destroy();
    }
}

附上一段详细的正确代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webviewRelativeLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
 
<WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/headerAlarmsWebViewTxt"
    android:layout_marginBottom="0dip"
    android:hapticFeedbackEnabled="true"
    android:overScrollMode="never"
    android:scrollbarAlwaysDrawVerticalTrack="false"
    android:scrollbars="none" />
 
 </RelativeLayout>
Then you assign it to an instance variable e.g. :
 
_layout = (RelativeLayout) findViewById(R.id.webviewRelativeLayout);
webView = (WebView) findViewById(R.id.webView1);
and on Destroy do something like this:
 
@Override
protected void onDestroy() {
    super.onDestroy();
    _layout.removeView(webView);
    webView.removeAllViews();
    webView.destroy();
}

一般看了这段代码就能明白问题所在了。

转载地址:

(136条消息) Error: WebView.destroy() called while still attached 的解决办法_极客公园的博客-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值