当出现要求关闭的对话框并选择“是”时,应用程序不会关闭,但看起来确实如此。看起来它可能正在关闭屏幕,但不是实际的应用程序。这是来自 MainActivity.java。有什么想法或建议吗?
private void showAlerExit() {
{
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
this);
alertDialogBuilder
.setMessage("Are you sure you want to quit?")
.setCancelable(false)
// button yes
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// if this button is clicked, close
// current activity
MainActivity.this.finish();
}
})
// button no
.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
}