BadTokenException for Dialog


I went to add a Dialog in a game that I am working on and encountered a BadTokenException. I initially thought that it was related to the library I was using for the game. Then I realized I was using an application context instead of an activity context(which is required for dialogs). For some reason the android documentation has an example using getApplicationContext.

Uncaught handler: thread main exiting due to uncaught exception
android.view.WindowManager$BadTokenException: 
Unable to add window — token null is not for an application

Leave a Reply

Your email address will not be published. Required fields are marked *