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 developer.android.com :(
Android :Unable to add window -- token null is not for an application
You should use Activity.this
instead of getApplicationContext()
$BadTokenException: Unable to add window -- token null is not for an application - Kotlin
It causes error, because it can't find the current view's context
to show the AlertDialog
So what you need to do is replacing val context = applicationContext
to
val context = view.context
Android Error: Unable to add window -- token null is not for an application
To add AlertDialog
to your Activity
or Fragment
you have to use your Activity
's instance, not your application's which you are doing in your code. Create your AlertDialog
like this :
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
And that should do the trick for you! : )
Related Topics
Android - Listen For Incoming Sms Messages
Disable Back Button in Android
How to Capture the "Virtual Keyboard Show/Hide" Event in Android
Set Color of Textview Span in Android
Listview Item Background Via Custom Selector
Android Java.Exe Finished With Non-Zero Exit Value 1
Android Fatal Signal 11 (Sigsegv) At 0X636F7D89 (Code=1). How Can It Be Tracked Down
Android Completely Transparent Status Bar
How to Create Custom Ratings Bar in Android
Changing API Level Android Studio
How to Restart Activity in Android
How to Change the Font on the Textview
Volley Jsonobjectrequest Post Request Not Working
Building and Running App Via Gradle and Android Studio Is Slower Than Via Eclipse