Code structure - liweiyap/narradir-android GitHub Wiki
Code structure
Considerations
Activities are pushed onto a stack when they are started/created, and popped from the same stack when they are finished/destroyed. We want to take advantage of this stack for the long-term ease of maintenance of the code.
When we navigate away from SettingsHomeActivity and the other individual Settings Activities, as well as HelpActivity, we want these to be popped, such that only the current Character Selection Activity remains on the stack (either AvalonCharacterSelectionActivity or SecretHitlerCharacterSelectionActivity).
Both AvalonCharacterSelectionActivity and SecretHitlerCharacterSelectionActivity should share the same SharedPreferences object, from which preferences are loaded and to which preferences are saved.
We have to name one of AvalonCharacterSelectionActivity and SecretHitlerCharacterSelectionActivity as the default (main) activity to be launched in AndroidManifest.xml. By default, we launch AvalonCharacterSelectionActivity, but in the onCreate() method, if we know that the last active game was instead Secret Hitler, we should finish AvalonCharacterSelectionActivity and start SecretHitlerCharacterSelectionActivity.
My original plan was to have a GameSelectionActivity as the main activity to be launched, from which we can select AvalonCharacterSelectionActivity or SecretHitlerCharacterSelectionActivity. However, I felt that having an additional Activity layer in the stack would complicate things a bit too much. For example, since we want our settings to be "global", we could navigate from GameSelectionActivity to SettingsHomeActivity, but then we don't have a previously started Activity to go "back" to via the Back Button. This might not be a problem if we were to use flags, but here I'm resisting the urge to use flags, in favour of simple pushing to and popping from the Activity stack.
Note that this arrangement makes it impractical to have a splash screen. However, in future, if we were to change the design of the code structure, then the notes for making a splash screen are found elsewhere in this Wiki.