我想在 onBackPressed() 事件的 android 中显示一个警报对话框
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
//@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
//Yes button clicked
break;
case DialogInterface.BUTTON_NEGATIVE:
//No button clicked
break;
}
}
};
但是在 onBackPressed() 事件中执行它时出现错误
@Override
public void onBackPressed() {
super.onBackPressed();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
}
错误:“ com.java.mypkg 泄露了最初添加在这里的窗口 com.android.internal.policy.impl.PhoneWindow$DecorView@406c3798 ”
我是否错过了什么。请帮忙。