How to “close” activity and all children activities
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:
MainActivityName.this.finish()<span style="color:#806030; ">;</span>
<br />MainActivityName.this.moveTaskToBack(true)<span style="color:#806030; ">;</span>
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):
Happy coding! (: