WindowManager: android.view.WindowLeaked

         

 

报错内容:

05-20 11:47:49.939 26318-26318/com.fanfareknowledge.pickupkinsfolk E/WindowManager: android.view.WindowLeaked: Activity com.fanfareknowledge.familytree.ui.web.WebActivity has leaked window android.widget.ZoomButtonsController$Container{f281d7d V.E..... ........ 0,0-1080,146} that was originally added here
        at android.view.ViewRootImpl.<init>(ViewRootImpl.java:375)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:271)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:90)
        at android.widget.ZoomButtonsController.setVisible(ZoomButtonsController.java:370)
        at com.android.org.chromium.android_webview.AwZoomControls.invokeZoomPicker(AwZoomControls.java:29)
        at com.android.org.chromium.content.browser.ContentViewCore.onScrollBeginEventAck(ContentViewCore.java:1075)
        at com.android.org.chromium.content.browser.ContentViewCore.nativeOnTouchEvent(Native Method)
        at com.android.org.chromium.content.browser.ContentViewCore.onTouchEventImpl(ContentViewCore.java:995)
        at com.android.org.chromium.content.browser.ContentViewCore.onTouchEvent(ContentViewCore.java:969)
        at com.android.org.chromium.android_webview.AwContents$AwViewMethodsImpl.onTouchEvent(AwContents.java:2372)
        at com.android.org.chromium.android_webview.AwContents.onTouchEvent(AwContents.java:1759)
        at com.android.webview.chromium.WebViewChromium.onTouchEvent(WebViewChromium.java:1918)
        at android.webkit.WebView.onTouchEvent(WebView.java:2295)
        at android.view.View.dispatchTouchEvent(View.java:8505)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2429)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2109)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2435)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2123)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2435)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2123)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2435)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2123)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2435)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2123)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2435)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2123)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2435)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2123)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2487)
        at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1785)
        at android.app.Activity.dispatchTouchEvent(Activity.java:2835)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2446)
        at android.view.View.dispatchPointerEvent(View.java:8712)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4239)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4093)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3621)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3687)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3647)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3776)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3655)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3833)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3621)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3687)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3647)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3655)

百度解释: 

webViwe的放大缩小按钮在设置显示状态下,显示和隐藏需要一定的时间过程

在界面消失之前,当清楚webView所有view

处理方式:

  @Override
    protected void onDestroy() {
        int sysVersion = Build.VERSION.SDK_INT;
        if (sysVersion >= 11) {
            setZoomControlGoneX(binding.infoAWebContent.getSettings(), new Object[]{false});
        } else {
            setZoomControlGone(binding.infoAWebContent);
        }
        super.onDestroy();
        binding.infoAWebContent.destroy();
    }

    /**
     * 2020-01-03  vic 添加
     *
     * @param view
     * @param args
     */
    public void setZoomControlGoneX(WebSettings view, Object[] args) {
        Class classType = view.getClass();
        try {
            Class[] argsClass = new Class[args.length];
            for (int i = 0, j = args.length; i < j; i++) {
                argsClass[i] = args[i].getClass();
            }
            Method[] ms = classType.getMethods();
            for (int i = 0; i < ms.length; i++) {
                if (ms[i].getName().equals("setDisplayZoomControls")) {
                    try {
                        ms[i].invoke(view, false);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setZoomControlGone(View view) {
        Class classType;
        Field field;
        try {
            classType = WebView.class;
            field = classType.getDeclaredField("mZoomButtonsController");
            field.setAccessible(true);
            ZoomButtonsController mZoomButtonsController = new ZoomButtonsController(view);
            mZoomButtonsController.getZoomControls().setVisibility(View.GONE);
            try {
                field.set(view, mZoomButtonsController);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }

当然,最好方法在不需要放大缩小时,不显示该view.

东西这么少,再写点吧。

webView的相关属性设置:

   binding.infoAWebContent.getSettings().setSupportZoom(true);
                binding.infoAWebContent.getSettings().setBuiltInZoomControls(true);
                binding.infoAWebContent.getSettings().setDisplayZoomControls(false);
                binding.infoAWebContent.getSettings().setDomStorageEnabled(true);
                binding.infoAWebContent.loadUrl(mS_url);
                binding.infoAWebContent.getSettings().setJavaScriptEnabled(true);
                
       
    binding.infoAWebContent.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
                binding.infoAWebContent.getSettings().setBuiltInZoomControls(true);
                binding.infoAWebContent.getSettings().setLoadWithOverviewMode(true);
                binding.infoAWebContent.getSettings().setDefaultTextEncodingName("UTF-8");

 

可以很明显看到跟zoom报错相关的属性有:

 binding.infoAWebContent.getSettings().setSupportZoom(true);
 binding.infoAWebContent.getSettings().setBuiltInZoomControls(true);
 binding.infoAWebContent.getSettings().setDisplayZoomControls(false);

这三条大概意思:

显示放大缩小的按钮,设置放大缩小的功能

如果保存放大缩小的功能,又不让项目崩溃:

  binding.infoAWebContent.getSettings().setSupportZoom(true);
                binding.infoAWebContent.getSettings().setBuiltInZoomControls(true);
                binding.infoAWebContent.getSettings().setDisplayZoomControls(false);

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值