Android implements the Global dialog box in the context issue. Windowmanager$badtokenexception Problem Solving

Source: Internet
Author: User

In the actual development process, we may have a lot of network requests where, this time we need some friendly hints, such as the progress of the dialog box

Ideally, we would write a global approach and then use the call directly on it.

Obviously, we should first think of writing a method directly in the application class of the project, and then doing progressdialog display and hiding, in this case, when we create the ProgressDialog object, It is natural to use the context object of the Getapplicationcontext, and then after it is run, it will burst. Windowmanager$badtokenexception the exception and forced the exit because we used the global application,

And dialog is only able to use activity as a parameter, and then we application the method inside, add an activity parameter can be, the problem is solved perfectly

/** * Display a dialog box */public static void Showprogressdialog (Context activitycontext,string msg) {progressdialog = new PROGRESSDI Alog (Activitycontext);p Rogressdialog.setprogressstyle (Progressdialog.style_spinner);p rogressdialog.setmessage ( msg);p rogressdialog.show ();}


Android implements the Global dialog box in the context issue. Windowmanager$badtokenexception Problem Solving

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.