About Progressdialog.show throw android.view.windowmanager$badtokenexception:unable to add window

Source: Internet
Author: User

Afternoon fiddling with the progressdialog, entering on the wrong: android.view.windowmanager$badtokenexception:unable to add window--token null was not a for an AP Plication, let me be baffled. I am using this method to implement the progress dialog box: Prodialog = Progressdialog.show (Getapplicationcontext (), "Sadfs", "dddddd", true);
Verify that

The cause of the exception is this getapplicationcontext (), Although the parameters here are also to get a context, but cannot use Getapplicationcontext () to get the context. You must use activity because there is only one activity to add a form


Workaround: Change Getapplicationcontext () in the parameter to xxactivity.this OK


The ProgressDialog object is dependent on a view, and the view is corresponding to an activity. So, here comes a life cycle problem, This.getapplicationcontext () takes the context of this application , Activity.this takes the context of the activity, the life cycle of the two is different, the former life cycle is the whole application, the latter life cycle is only its activity. and ProgressDialog should
It belongs to an activity, it is destroyed when the activity is destroyed, it will not exist again, but if you pass in This.getapplicationcontext (), it means that its life cycle is the entire application, which clearly exceeds its life cycle. So, here we can only use the activity's this.


Source: http://www.xuebuyuan.com/1358679.html

From for notes (Wiz)

About Progressdialog.show throw android.view.windowmanager$badtokenexception:unable to add window

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.