[안드로이드] android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application |
AlertDialog.Builder alert = new AlertDialog.Builder(getApplicationContext());
alert.setTitle("타이틀");
alert.setMessage("메세지");
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Todo
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Todo
}
});
alert.show();
Android documents suggests to use getApplicationContext(); but it will not work instead of that use your current activity while instantiating AlertDialog.Builder or AlertDialog or Dialog... Ex:
or
|
AlertDialog.Builder alert = new AlertDialog.Builder(LoginActivity.this);
alert.setTitle("타이틀");
alert.setMessage("메세지");
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Todo
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Todo
}
});
alert.show();
*참고
stackoverflow 질문글 : https://stackoverflow.com/questions/2634991/android-1-6-android-view-windowmanagerbadtokenexception-unable-to-add-window
댓글 영역