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! : )
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
In AlertDialog - Unable to add window -- token null is not valid; is your activity running?
- Pass the current activity context instead Application context in AlertDialog.Builder().
- Set the AlertDialog type to WindowManagerTypes.ApplicationPanel intead of Toast
AlertDialog.Builder builder = new AlertDialog.Builder(context);//current activity.
b.Window.SetType(WindowManagerTypes.ApplicationPanel);
Unable to add window -- token null is not for an application inside OnReceive of Broadcast Receiver
Just removing my receiver from manifest.xml solved my issue. Thanks.
Alert Dialog Exception Unable to add windows -- token null is not for an application, what context should I give?
To show a Dialog
you need to use the Activity
context. Here you're using the Application
context which is incorrect.
productsAdapter = new ProductsAdapter(getApplicationContext(), 0);
To make it work change the above line to use the Activity
context. Since this call is made inside an Activity
you can use:
productsAdapter = new ProductsAdapter(this, 0);
But this is not the best way to do so because your parameter type is Context
and not Acticity
and as it's happening to you, the context may be incorrect.
A better idea is to provide a click listener callback to your Activity
and manage the Dialog
inside the Activity
instead of the Adapter
.
Unable to add window -- token null is not for an application from Service
You cannot show Dialogs from a Service context.
I suggest you to open an Activity that actually shows the dialog, or take a look at this answer to learn how to show system alerts.
https://stackoverflow.com/a/19269931/1725088
Unable to add window -- token null is not valid; is your activity running? in AutoCompletetextView
There is some dialog or other kind of window being added before your activity is shown to user , thus there is no token available to added a new window ,try using post on your view it might help you to solve your error.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
autoexheader.post(new Runnable() {
@Override
public void run() {
autoexheader.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (charSequence.length() == 0) {
autoexheader.showDropDown();
}
}
@Override
public void afterTextChanged(Editable editable) {
if (editable.length() == 0) {
autoexheader.showDropDown();
}
}
});
}
});
Related Topics
Converting Utc Dates to Other Timezones
Measuring a View Before Rendering It
Display Data After Every 10 Seconds in Android
Why Is Android Webview Refusing User Input
Android Device as a Receiver for A2Dp Profile
Change Text Color of Selected Item in Spinner
Play an Audio Clip Onto an Ongoing Call
Permission Denied (Missing Internet Permission): But Permission Is Given
How to Implement Autocompletetextview with Listview
How to Get Charles Proxy Work with Android 7 Nougat
What Is the Equivalent of Actionbar in Earlier Sdk Versions
Resources$Notfoundexception: File Res/Drawable/Abc_Ic_Ab_Back_Material.Xml
Render Error in Android Studio 3.0 Layout Editor
Android Picasso Library, How to Add Authentication Headers
Android Viewpager Setcurrentitem Not Working After Onresume