I am having trouble to figure out how to implement a main menu correctly. The following thing is going on:
MainMenu -> ActivityA -> ActivityB -> ActivityC -> MainMenu
I want to supress being able to go back to ActivityC (and ActA & ActB likewise) when I am back at the MainMenu. My first clue was to override the back-button and do nasty stuff like killing the App by its PID, but I know that’s discouraged, so…
There are many interesting flags for intents, like FLAG_ACTIVITY_CLEAR_TOP, FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_NO_HISTORY, but none of them works.
FLAG_ACTIVITY_CLEAR_TOP causes to close the App immediately as I reach the main menu (best result so far…), the others had no effect at all, pressing back just returned be back to ActivityC.
I tested them all, not only these four, all activity flags… I also tested to define android:clearTaskOnLaunch=”true” for the main menu, without success.
Oh yeah, I am dealing with 2.2, API level 8
Any suggestions are highly appreceated.
Best Regards!
The sollution suggested over here is perfect:
https://stackoverflow.com/a/8678500/1841940
I register a BroadCastListener on all Activities that should be removed from the backstack and when I reach the main menu, I just send the broadcast and all receivers call finish().
This works really great!