Repository navigation
Code structure
Li-Wei Yap edited this page Mar 31, 2021
·
3 revisions

-
Activitiesare 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
SettingsHomeActivityand the other individual Settings Activities, as well asHelpActivity, we want these to be popped, such that only the current Character Selection Activity remains on the stack (eitherAvalonCharacterSelectionActivityorSecretHitlerCharacterSelectionActivity). - The alternative to this would be to use
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)orintent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP). However, this might create cycles of Activities / chains of events that are difficult to visualise or test.
- When we navigate away from
- Both
AvalonCharacterSelectionActivityandSecretHitlerCharacterSelectionActivityshould share the sameSharedPreferencesobject, from which preferences are loaded and to which preferences are saved. - We have to name one of
AvalonCharacterSelectionActivityandSecretHitlerCharacterSelectionActivityas the default (main) activity to be launched inAndroidManifest.xml. By default, we launchAvalonCharacterSelectionActivity, but in theonCreate()method, if we know that the last active game was instead Secret Hitler, we should finishAvalonCharacterSelectionActivityand startSecretHitlerCharacterSelectionActivity.- My original plan was to have a
GameSelectionActivityas the main activity to be launched, from which we can selectAvalonCharacterSelectionActivityorSecretHitlerCharacterSelectionActivity. However, I felt that having an additionalActivitylayer in the stack would complicate things a bit too much. For example, since we want our settings to be "global", we could navigate fromGameSelectionActivitytoSettingsHomeActivity, 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 theActivitystack. - 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.
- My original plan was to have a