views:

70

answers:

1

I'm writing a game for Android. My GUI has the following basic screens (i.e. the information and interactions required on each of these would take up the whole display):

  1. Main menu (let you start a new game, enter settings, see high scores, see about screen)
  2. Game screen i.e. where the actual game is played.
  3. Settings screen.
  4. High scores screen.
  5. About screen (i.e. credits and a back button)
  6. Game over screen (arrived at when the game ends)
  7. Pause screen (pauses game and can access settings)

The following are some example transitions the user might make between these screens:

1->2->7->2->6 (starts new game, pauses game, returns to game, finishes game) 1->5->1->4->1 (views about screen, goes back to main, views score screen, goes back to main)

I'm really confused about when to have just one activity that switches layouts and when to create new activity classes. For example, when my game loads, I have a "main" activity that loads the main menu layout. When you click the settings button, I launch a "settings" activity (which uses android's standard settings GUI). For the moment, when you start a game, I switch the layout of "main" to the game screen layout (which just contains one big surface view). I'm not really sure what the best way to integrate the game over screen, high score screen, about screen etc.

Creating a new activity for each seems really heavy weight to me. There's quite a lot of boiler plate code involved for each activity. Plus, communication between activities seems like a pain as you have to use bundles. Using just one activity means I can just share object fields directly. It seems that using layouts for the above would be more compact.

Can anyone give me some recommendations?

+1  A: 

In my games, I use a Activity for most... activities (play, see help, see high scores, change settings). Being in one application means that you may share some things (for example the current game) in one singleton. You probably don't need a lot of communication between Activities, mainly the "order" (that is the reason why you go to this activity, for example the new high score in the High Scores screen) and it may be sent through the Intent (I use the URL instead of the Bundle).

A few things can be made in dialogs (I use them to launch a new game, or to type the name of the player). My rule is that if the screen change completely, then it's a new Activity. This way the layouts are simple.

dystroy