티스토리 뷰

 
...
// AlertDialog 등록 및 이벤트 리스너
        builder = new AlertDialog.Builder(getApplicationContext());
        builder.setMessage(getString(R.string.dialog_logout));
 
        builder.setPositiveButton("YES"new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                goToLoginActivity();
            }
        });
 
        builder.setNegativeButton("NO"new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                alertLogin.dismiss();
            }
        });
        alertLogin = builder.create();
...
 
 
 
 
Colored by Color Scripter
 

AlertDialog 생성하는데 BadTokenException 발생

원인은 new AlertDialog.Builder를 할 때 매개변수에 getApplicationContext()를 넣어서 발생한 것

 

해결방법 :

getApplicationContext() → ThisActivity.this

댓글
댓글쓰기 폼