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