0

当出现要求关闭的对话框并选择“是”时,应用程序不会关闭,但看起来确实如此。看起来它可能正在关闭屏幕,但不是实际的应用程序。这是来自 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();
    }

}
4

1 回答 1

0

利用

moveTaskToBack(true);

目的moveTaskToBack

http://developer.android.com/reference/android/app/Activity.html moveTaskToBack(boolean true)将包含此活动的任务移动到活动堆栈的后面。

于 2013-10-27T17:19:48.167 回答