Nabeel Ahmed
Nabeel Ahmed

Reputation: 18

How to Exit an application when my app consists of multiple activities?

How to exit application in android when I have multiple activities in that app?

I have tried finish() and System.exit(0), but none of them worked. What it does is just go to the previous activity.

Here is my code:

                 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();

Upvotes: 0

Views: 534

Answers (1)

RamaKrishnan
RamaKrishnan

Reputation: 179

call finishAffinity(); method to finish all the previous activities.

 finishAffinity();

Upvotes: 3

Related Questions