I am using AndEngine for my game. In that I want to give option to user when they click on an image, one alert dialog should pop up. my code is below.
here is the method
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 1:
AlertDialog.Builder builder = new AlertDialog.Builder(MyGame.this.getApplicationContext());
builder.setMessage("Hello");
AlertDialog alert = builder.create();
return alert;
default:
return null;
}
}
and I am calling this method by this statement :
{
onCreateDialog(1).show();
}
And i am getting this error message :
E/AndroidRuntime(672): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
onCreateDialog(1).show();is wrong.Call
showDialog(1);instead.And also change your Builder like this: