The following question has been presented to me while solving an exam on the Android and iOS systems, and despite understanding the Android backstack, i have no idea how to answer it.
How could you implement an Android application which relied on 5 Activites, and, upon openning them in the order 1 -> 2 -> 3 -> 4 -> 5, when in the 5th Activity the "back" button was pressed, the 5th Activity would close, allowing the 3rd to pop-up, and when "back" was pressed again, the same between the 3rd and 1st Activities. All this while also closing the 2nd and 4th Activities.
The question required a reply with emphasis on the Android system's backstack.
Backstack:
(all 5 activities are openned in the abovementioned order)
1, 2, 3, 4, 5
5th Activity closed
5, 4, 3, 2, 1
5, 3, 1
3rd Activity closed
3, 1
3, 1
1st Activity closed
1
Application closes
What I have tried:
I could very easily describe a programmatic implementation of what was requested, mainly tracking each Activity's openning order and upon closing the present one, if it was the 5th, i'd make the 2nd and 4th instantly close upon their onCreate() being called, allowing the odd-numbered Activities to appear to be the only existing ones.
However, this would not actually close the 2nd and 4th Activities and doesn't rely on the Backstack's functionality at all.