how to finish all activities and close the application in android?

rahul picture rahul · Nov 26, 2013 · Viewed 48.3k times · Source

My application has the following flow:

Home->screen 1->screen 2->screen 3->screen 4->screen 5>Home->screen 2->Home->Screen 3

My problem is that when I am trying to close the application then Home activity opens everytime when I am trying to close the application.

I just want to close the application when user presses the back key of device on home screen.

Answer

Ragaisis picture Ragaisis · Nov 26, 2013

There is finishAffinity() method that will finish the current activity and all parent activities, but it works only in Android 4.1 or higher.