Let's say I have 4 activities in my app:<br /> A (main activity)<br /> B<br /> C<br /> D
I would like that pressing back in Activity A always produce application exit. In my case if activity flow goes like this A > B > C > A, then if I push back button, I will go to activity C. I want, at that moment, my app to exit.
I assume, app should somehow delete activity history when main activity is active.<br /> How is this to be done?
When you launch your home activity do so with the clear top flag set. This causes the back stack to be cleared.
Intent intent = new Intent(this, HomeActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent);Answer2:
If you want the above behaviour then use the <a href="http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP" rel="nofollow">FLAG_ACTIVITY_CLEAR_TOP</a> to launch A. This will clear the all the activities above A