Android 1.6: “android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application”

Instead of :
Context appContext = this.getApplicationContext();
you should use a pointer to the activity you’re in (probably this).

I got bitten by this today too, the annoying part is the getApplicationContext() is verbatim from 🙁

You cannot display an application window/dialog through a Context that is not an Activity. Try passing a valid activity reference

Ditto on the getApplicationContext thing.

The documents on the android site says to use it, but it doesn’t work…grrrrr 😛

Just do:

dialog = new Dialog(this); 

“this” is usually your Activity from which you start the dialog.

Leave a Comment