Android. View. windowmanager $ badtokenexception: unable to add window

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.