当出现要求关闭的对话框并选择“是”时,应用程序不会关闭,但看起来确实如此。看起来它可能正在关闭屏幕但不是实际的应用程序。这来自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();
}
}
答案 0 :(得分:0)
使用
moveTaskToBack(true);
moveTaskToBack
的目的:
http://developer.android.com/reference/android/app/Activity.html moveTaskToBack(boolean true)
将包含此活动的任务移至活动堆栈的后面。