How to “close” activity and all children activities

Hello Everybody,

I was implementing a multi activities application and was really surprised that it is not easy to close all of them from the main activity when user hits ‘Exit’ 🙂

In general, in Android way it is not logical to “close” something, it is better to move something to the background 🙂 I found it after a day of fighting with activities.

First of all, ** and it is very important **, it is correct to place ActivityName.this.finish(); after any startActivity() invokation!

I have found following cool way to close an application for sure:


By this way activity and all her children will be moved to the background and you will never see annoying child activity when hit ‘Exit’ button on your main screen.

Update your manifest file and root activity params (http://developer.android.com/guide/topics/manifest/activity-element.html):

android:label=”@string/app_name”
android:clearTaskOnLaunch=”true”
android:alwaysRetainTaskState=”false”
android:finishOnTaskLaunch=”true”
android:launchMode=”singleTask”
android:screenOrientation=”portrait”>

Happy coding! (:

Best regards,

Yahor