Vishal Pawar
Vishal Pawar

Reputation: 4340

Why application throwing exception while starting progress dialog throw application

Here is the exception which I am getting while handler try start the Progress Dialog from application

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
 at android.view.ViewRoot.setView(ViewRoot.java:531)
 at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
 at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
 at android.app.Dialog.show(Dialog.java:241)
 at android.app.ProgressDialog.show(ProgressDialog.java:107)
 at android.app.ProgressDialog.show(ProgressDialog.java:90)

Please suggest solution if anybody knows

Upvotes: 1

Views: 332

Answers (4)

MKJParekh
MKJParekh

Reputation: 34311

Change Your Context To ActivityName.this

Because this BadToken Exception ,So In your case you are adding the Progress Dialog to Your Activity Screen but passing the wrong context.

Upvotes: 3

Arun
Arun

Reputation: 1668

It would be good if you had paste your code. By the error logs its problem with your context. You might be passing a different context for the activity you are displaying.

Upvotes: 1

Abhinava
Abhinava

Reputation: 1030

Would have been lot easier if you pasted your code... but still there can be 2 possible reasons. 1. Context of wrong Activity. 2. you said that you are launching by a handler, please check the handler is of same activity for which you are using context in order to launch the dialog.

Upvotes: 0

Piyush Patel
Piyush Patel

Reputation: 1825

For progress dialog use context obtained by, below method

getApplicationContext();

Upvotes: 0

Related Questions