Dialog throwing "Unable to add window — token null is not for an application” Error

This is a common problem, you can not reach the context first and therefore it is null. What you need to do here is that if you use "ActivityName.this" instead of getApplicationContext(),context etc. your problem will be resolved.

Like this;
 
/*
This is a common problem, you can not reach the context first and therefore it is null.
What you need to do here is that if you use "ActivityName.this" instead of getApplicationContext(),
context etc. your problem will be resolved.
*/
//For example Alert Dialog;
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); //Activity name
alertDialog.setMessage("Test Messages");
alertDialog.setPositiveButton("OK", listener);
AlertDialog alert = alertDialog.create();
alert.show();

Yorumlar

Bu blogdaki popüler yayınlar