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

3

8

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, markers and so on. When the user clicks on one of the markers info window another activity is launched and at this moment i get a bunch of red error messages in the log, though the app does not crash. These messages (the init is in the title) seem to talk about the ZoomButtons and touch events. As for ZoomButtons or touch events (multitouch) in the code, there are only 2 lines :

map.setBuiltInZoomControls(true);
map.setMultiTouchControls(true);

and not any dialog…

  • if i write:

    map.setBuiltInZoomControls(false); map.setMultiTouchControls(false);

the red error messages disappear but of course the user cannot zoom in or out in any way…

As the error (with the "true" parameter) occurs only when launching another activity i thought that i have to add something in on pause() ie:

onPause(){
map.setBuiltInZoomControls(false);
map.setMultiTouchControls(false);
super.OnPause();
}

---- but doing so does not change anything… Any hint??? - Thanks in advance!

Graven answered 2/12, 2014 at 16:44 Comment(3)
Found the answer (not the solution) by myself: when i click on the marker and open the infoWindow the osmdroid zoomButtons appear (they must have some listener getting the tap on the map i guess); if i click on the infoWindow (in order to launch the 2° activity) while they always are present the error occurred; i i wait till they vanish: no error. So i have probably to look at the osmdroid source for seeing wether it s possible to change the zoomButtons appear/disappear behavior which by the way is not really useful.Graven
Thanks to you and Noni, I could handle with this! Thanks!Unoccupied
documented at osmdroid issue tracker here: github.com/osmdroid/osmdroid/issues/328Gelasias
B
16

Add this to your activity:

@Override
public void finish() {
    ViewGroup view = (ViewGroup) getWindow().getDecorView();
    view.removeAllViews();
    super.finish();
}
Blastema answered 11/2, 2015 at 13:10 Comment(0)
S
8

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);
Sharl answered 19/2, 2015 at 7:9 Comment(1)
Is it a solution to remove leaking buttons? They are usually left there because they are deemed useful by developers...Lucilla
D
1

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);
    }
Detector answered 7/7, 2016 at 4:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.