I'm a computer hobbyist who is working on a very small trivia game for the Android platform.
In this game, I move the player between multiple activity/view pages (entry, question page, answer page, ultimate score page). I've created a question object that contains all data related to a single trivia question (question, four answers, pointer to correct answer, related comments that the computer makes when responding to the player's guess), and I've successfully populated an ArrayList of Question objects with data that I DOM parsed from an XML file.
What is an acceptable way of passing this data back and forth between activities as the game progresses? How can I keep these data objects alive as the user moves through the game?
I understand that global variables are highly discouraged. I have also learned that the Singleton design pattern poses many of the problems said to be associated with global variables. I'm stumped when it comes to finding alternatives to those approaches.
I understand the basics of the MVC approach. My activity *.java files are the controller files, and they're linked to the layouts (views) I've created with XML. I have two "model" objects that need to be maintained and modified as the game progresses: (1) the question-bank ArrayList mentioned above and (2) some sort of "PlayerProgress" object that contains all data related to the player's progress in the game.
These data objects are first instantiated at the beginning of the game, but I don't know how to keep them alive as the user moves between activities. I know that I can pass information between activities as EXTRAS, but EXTRA don't seem to be intended for this purpose. Even if EXTRAS worked for the player progress properties, I don't think I can use them to pass an ArrayList of 25-50 question objects between activities.
I have looked into serialization and parcelable, but it seems weird (and possibly inefficient) to basically decompose and then recompose my data model objects every time the user moves back and forth between different activities/views. If one of these is an acceptable/common way to accomplish this, I can happily plunge forward, but I wanted to check with others first.
I keep butting my head against this in different programming languages, and suspect that there is some bigger part of the picture that I'm failing to understand. I've read through the descriptions of objects and application life cycles in many different resources, but I still haven't managed to figure out the solution to this basic question.
I'm asking this question ("What is an acceptable way of passing data objects back and forth between activities as the game progresses") in the context of my silly trivia game, but I'm really concerned with getting a handle on the bigger picture. If folks don't have the time to spell out something so seemingly basic, perhaps you can point me to descriptions in other books that you found useful? (I've got a few slots open in my Safari bookshelf, and can track down copies of almost any technical publication.)
Thanks.