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

activity-stack, android, android-activity

Solution

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

Problem

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.

Original source

Related problems