Android. View. windowmanager $ badtokenexception: unable to add window -- token Android. App. localactivitymanager $ localactivityrecord @ 45f48c40 is not valid; is your activity running?
Today, I encountered a problem when writing a Google Map for Android. I added an overlay to the map and wanted to play the dialog box dilay when I clicked the overlay icon,
After writing the code in this way, the test reports the above exception.
The Code is as follows:
// This is an inherited itemizedoverlay .
@ Override
Public Boolean ONTAP (int I ){
// Todo auto-generated method stub
Overlayitem item = allmapoverlays. Get (I );
Alertdialog. Builder dialog = new alertdialog. Builder (context );
Dialog. settitle (item. gettitle ());
Dialog. setmessage (item. getsnippet ());
Dialog. Show ();
Return true;
}
The problem is that the context cannot use getapplicationcontext (). The context obtained by this must use the context obtained by your_activity.this.
I am using the last one, or on a business trip.
So I thought about my actual running environment. My map is in tabactivity, so the administrator of the current form should be owned by the tabactivity at the upper level, not my map activity.
Therefore, the context obtained by using getparent () is successfully run.