Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView with BuiltInZoomControls throwing Exceptions and crashing

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

like image 667
amsiddh Avatar asked Aug 09 '12 18:08

amsiddh


2 Answers

Add this to your activity:

@Override
public void finish() {
    ViewGroup view = (ViewGroup) getWindow().getDecorView();
    view.removeAllViews();
    super.finish();
}
like image 68
Simon Rolin Avatar answered Sep 18 '22 23:09

Simon Rolin


Make sure you do

setVisible(false);

in onDestroy() before you call the super or call destroy() on your webView object.

like image 40
Assaf Gamliel Avatar answered Sep 18 '22 23:09

Assaf Gamliel