6

I am using a WebView with BuiltInZoomControls enabled. I can view the data in WebView properly and also i can use the zoom controls to zoom it. But when i click back to move to previous screen i get Exception and app crashes. ( Other thing it works properly if i don't use zoom controls. i mean zoom controls are enabled in WebView but i have not used, just viewed the WebView content and clicked back.)

WebView:

mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setSupportZoom(true);
mWebView.getSettings().setPluginState(PluginState.ON);

Exceptions:

Activity com.web.ui.DetailActivity has leaked window android.widget.ZoomButtonsController$Container@4110c4e0 that was originally added here
.....

FATAL EXCEPTION: main
E/AndroidRuntime(670): java.lang.IllegalArgumentException: Receiver not registered: android.widget.ZoomButtonsController$1@4110c2d0

....

And onDestroy of Activity i am also adding this:

mWebView.getSettings().setBuiltInZoomControls(false);

Any idea what could be the issue. Need help.

Thanks

4

4 回答 4

13

将此添加到您的活动中:

@Override
public void finish() {
    ViewGroup view = (ViewGroup) getWindow().getDecorView();
    view.removeAllViews();
    super.finish();
}
于 2015-02-11T13:11:55.207 回答
3

确保你这样做

setVisible(false);

onDestroy()您调用 super 或在 webView 对象上调用 destroy() 之前。

于 2013-02-05T16:44:07.970 回答
1

我遇到了同样的问题并尝试了给出的解决方案,但是我一直遇到异常。唯一对我有用的代码是

public void onDetachedFromWindow(){
    super.onDetachedFromWindow();
    setVisible(false);
}

但是,我仍然不明白为什么setVisible(false);onDestroy(). 如果有人知道解释,如果您可以发布/评论,我将不胜感激。

于 2014-07-14T20:07:41.900 回答
0

我遇到了同样的问题。我通过在三秒后调用 WebView.destroy() 来修复它(直到缩放控件的动画完成)

@Override
    protected void onDestroy() {
   mWebView.postDelayed(new Runnable() {

                @Override
                public void run() {
                    try {
                        mWebView.destroy();
                    } catch (Exception ex) {

                    }
                }
            }, 3000);
于 2013-07-29T12:26:14.830 回答