android.view.WindowLeaked: Activity has leaked window android.widget.ZoomButtonsController$Container that was originally added here

前端 未结 3 1082
醉梦人生
醉梦人生 2021-02-15 12:01

Working with maps i have an activity which is launched when no connection is available and uses offline maps (MapQuest). The activity runs fine, map is shown, and all overlays,

相关标签:
3条回答
  • 2021-02-15 12:27

    Add this to your activity:

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

    The problem with this leak window does not appear in the following version of Android 3.0 , so,you can try to do :

        // enabled zoom support
        getSettings().setSupportZoom(true);
        getSettings().setBuiltInZoomControls(true);
    
        // but,We should hide this button, otherwise in the version
        // of Android 3 and above, there is a window leak.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            // call requies API Level 11 ( Android 3.0 + )
            getSettings().setDisplayZoomControls(false);
        }
    
    0 讨论(0)
  • 2021-02-15 12:42

    I was having the exact same problem... thanks to you pointing out that it is caused by (likely) when the zoom controls are still visible. I tested it, and that was correct. When I pressed the back button with the zoom controls showing, it would show that leak error, if I waited until the controls faded away (they do after you stop scrolling), then there was no leak error.

    A little research in WebSettings provided a method that doesn't show the zoom controls, which means it doesn't leak at anytime you want to press the back button. It does still zoom with the pinch effect though. The only disadvantage to using this method is that your controls won't show. But to me, that's worth it, since most users know about pinch zoom for all apps.

    Here is what I used:

    // make sure your pinch zoom is enabled
     webView.getSettings().setBuiltInZoomControls(true);
    
    // don't show the zoom controls
     webView.getSettings().setDisplayZoomControls(false);
    
    0 讨论(0)
提交回复
热议问题