I have a sequence of activity launches below:
Home Activity -> 2nd Activity -> 3rd Activity - > 4th Activity
What I want to achieve is that when the 3rd activity launches the 4th activity, it clears activities 2 and 3 from the backstack. Thus, clicking back on the 4th activity returns to the home activity
i.e. The user should still be able to go back from the 3rd activity to the 2nd, but once the 4th activity is launched, activities 2 and 3 removed.
What's the configuration to achieve this?
Although all the answers were useful, and as I only had 2 activities that I wanted to close this is what I did:
startActivityForResult()
on Activity 2RESULT_OK
before I call finish()
on Activity 3.onActivityResult()
, that way I know Activity 4 has been lauched, so I can finish Activity 2.Therefore both Activity 2 and 3 are closed upon launching of activity 4.