Skip to content Skip to sidebar Skip to footer

"windowmanager Badtokenexception-unable To Add Window"why I Am Getting This Exception While Using Google Maps?

I am using google map to show(pin) different places.After showing different palces when hit the back button it redirects to my home screen.Around 10-15 seconds later my application

Solution 1:

Globally declare this value.

int i=0;

In the above code make the following changes.So that it will update only once.(windowmanager badtokenexception-unable to add window)this exception will not happen again.But i dont know whether it is right method to do.If anyone got better answer,you are welcome.

@OverridepublicvoidonLocationChanged(Location location) {


               for(;i<=0;i++)
               {

                   map.clear();

                    lat=location.getLatitude();
                    lon=location.getLongitude();

                      mp = newMarkerOptions();

                       mp.position(newLatLng(lat, lon));
                       map.addMarker(mp);
                       mp.title("My Location");

                   map.animateCamera(CameraUpdateFactory.newLatLngZoom(
                              newLatLng(lat, lon), 13));

                            GoogleapicallexeTask=newGoogleapicall();
                              exeTask.execute();

               }


        }

Solution 2:

you can try ,

  1. create boolean static variable ,

    privatestaticbooleanisActivityOpen=false ; 
    
  2. update the value at onCreate()

    isActivityOpen  = true;
  3. Check value at dialog show / dismiss method

    if(isActivityOpen )
    {
      Dialog.show();
    } 
    
  4. Disable value in onDestroy()

    isActivityOpen  = false;

Post a Comment for ""windowmanager Badtokenexception-unable To Add Window"why I Am Getting This Exception While Using Google Maps?"