Android App - Game States

Different game states were necessary for my app to make the flow and persistence  between screens manageable. Any state change results in game data save, so it is not possible to cheat if for example a card battle is going badly and you want to quit and restart.. the game will automatically persist the battle in the background (not blocking the UI) and reload the exact state when the game is restarted. Of course the advantage of this is that you can quit whenever you like and be able continue from exactly where you were last time.

cardsflow.png

Saving and loading data between the states however is not completely trivial especially if you have to save large chunks that must later be read from disk. This was my initial design using caching (implemented through a singleton that can be shared across activitites). The background save is implemented using android ASyncTask, a transaction design is implemented to ensure that partial-corrupt data is not saved. 

StatesDesign.png