-1

Firstly, I've tried almost all the solutions about this issue but I can not find solution.

Question: When user press exit button in my application I want to kill all application. There is a few methods like finish(); or System.exit(0); If I use on MainActivity, they are work. I want this, If I MainActivity or A Activity or B Activity doesnt matter which Activty when I press exit button just kill all application and go back phones menu.

Ibrahim BOLAT
  • 223
  • 1
  • 6
  • 18

1 Answers1

10

This will do the trick

finishAffinity();

Check this for deails: API Description

Finish this activity as well as all activities immediately below it in the current task that have the same affinity. This is typically used when an application can be launched on to another task (such as from an ACTION_VIEW of a content type it understands) and the user has used the up navigation to switch out of the current task and in to its own task. In this case, if the user has navigated down into any other activities of the second application, all of those should be removed from the original task as part of the task switch.

Note that this finish does not allow you to deliver results to the previous activity, and an exception will be thrown if you are trying to do so.

Sreehari
  • 5,621
  • 2
  • 25
  • 59