How to safely turn WebView zooming on and off as needed

前端 未结 9 1230
后悔当初
后悔当初 2020-12-15 01:06

As mentioned in this unanswered question: WebView throws Receiver not registered: android.widget.ZoomButtonsController

By turning the WebView zoom controls on and of

相关标签:
9条回答
  • 2020-12-15 01:38

    If you are stumbling upon this question, be sure to check the bug report first to see what the status is from Google, but otherwise here is a workaround that is working so far so good for me:

    Add this line to your onDestory() method:

    webView.getSettings().setBuiltInZoomControls(true);
    
    0 讨论(0)
  • 2020-12-15 01:38

    java.lang.IllegalArgumentException: View not attached to window manager exception mostly occurs when there is a dialog (i.e. Progress Dialog) and you are dismissing it when the Activity has closed. Could you tell if your Activity indeed has a Progress Dialog in it , so that I can continue with my analysis ? Also post your Activity's code snippet which might help us identifying why your app is crashing ...

    Also you say you don't face application crash often frequently, so do a test to confirm my suspicions. When your application is running change your screen orientation , and do it a couple of times , after few minutes, preferably when there is Progress Dialog involved in doing some work. It might crash the application which should tell us that the error is because the Progress Dialog isn't dismissing correctly.

    My Theory : When you switch orientations, Android will create a new View. You're probably getting crashes because your background thread is trying to change the state on the old one. (It may also be having trouble because your background thread isn't on the UI thread)

    0 讨论(0)
  • 2020-12-15 01:42

    This solution works fine, you simply need to remove the webview from the layout before destroying it:

    @Override
        public void onDestroy() {
            if (webView!=null && webView.getParent()!=null){
                ((ViewGroup)webView.getParent()).removeView(webView);
                webView.destroy();
                webView=null;
            }
            super.onDestroy();
        }
    

    No handlers, no delays, i think it's the best solution

    0 讨论(0)
  • 2020-12-15 01:49

    Add this to your activity:

    @Override
      public void finish() {
          ViewGroup view = (ViewGroup) getWindow().getDecorView();
          view.removeAllViews();
          super.finish();
    }
    
    0 讨论(0)
  • 2020-12-15 01:52

    I have the same issue here: Existent app blowing up with android 3.0 XOOM. ZoomButtonsController Leak?

    This happens when there's an exception that happens before registerReceiver is called and then you try to unregisterReceiver later without it ever been registered.

    It's probably a android 3.0 bug.

    0 讨论(0)
  • 2020-12-15 01:54

    Put this line in onDestroy works for me:

    webView.setVisibility(View.GONE);

    0 讨论(0)
提交回复
热议问题