I am looking for a clean way to implement pre- and post-activities for a central activity, basically pre-level and post-level activities for a game level activity sandwiched in between. The pre- and post-level activities are similar, but have enough differences that I would like to use two different activities with different layouts.
Here’s a short rundown of how I imagine the activity ordering (Back would be pressing the back button, action would be interacting with the activity to move forward):
- Main Menu Activity
- Back -> Quit
- Action -> Pre-Level Activity
- Pre-Level Activity
- Back -> Main Menu Activity
- Action -> Game Activity
- Game Activity
- Back -> Paused Activity
- Action -> Post-Level Activity
- Paused Activity
- Back -> Return to Game Activity
- Action -> Post-Level Activity
- Post-Level Activity
- Back -> Main Menu Activity
- Action -> Pre-Level Activity for next level
Any suggestions for how to best implement such an activity loop?
Read this document: Task and Back Stack
If you want to do other operations then activity operations e.g. pause the game. You can handle the onBackPressed() function to do other things then finish the activity