【问题标题】:How to Exit an application when my app consists of multiple activities? [duplicate]当我的应用程序包含多个活动时,如何退出应用程序? [复制]
【发布时间】:2019-08-12 01:41:49
【问题描述】:

当我的应用程序中有多个活动时,如何退出该应用程序?

我尝试过finish()System.exit(0),但都没有奏效。它所做的只是转到上一个活动。

这是我的代码:

                 boolean insertionStatus = mydb.DataInsertion(email,  password, username, fathername, contact, birthday, user_address);

                        if (insertionStatus)
                        {
                            alert.setTitle("Registration Status");
                            alert.setMessage("You are successfully registered!\nDo you want to login now?");
                            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Intent intent = new Intent(RegistrationActivity.this, LoginActivity.class);
                                    startActivity(intent);
                                }
                            });

                            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    System.exit(0);
                                }
                            });
                            alert.create().show();

【问题讨论】:

    标签: android activity-finish system.exit application-close


    【解决方案1】:

    调用finishAffinity();方法完成之前的所有活动。

     finishAffinity();
    

    【讨论】:

    • @NabeelAhmed 编码快乐!!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-31
    • 1970-01-01
    相关资源
    最近更新 更多