When to use new layouts and when to use new activities?
<p>I'm making a game in Android and I'm trying to add a set of menu screens. Each screen takes up the whole display and has various transitions available to other screens. As a rough summary, the menu screens are:</p>

<ol>
<li>Start screen</li>
<li>Difficult select screen</li>
<li>Game screen.</li>
<li>Pause screen.</li>
<li>Game over screen.</li>
</ol>

<p>And there are several different ways you can transition between screen:</p>

<p>1 -> 2</p>

<p>2 -> 3</p>

<p>3 -> 4 (pause game)</p>

<p>4 -> 1 (exit game)</p>

<p>4 -> 3 (resume game)</p>

<p>3 -> 5 (game ends)</p>

<p>Obviously, I need some stored state when moving between screens, such as the difficulty level select when starting a game and what the player's score is when the game over screen is shown.</p>

<p>Can anyone give me some advice for the easiest way to implement the above screens and transitions in Android? All the create/destroy/pause/resume methods make me nervous about writing brittle code if I'm not careful.</p>

<p>I'm not fond of using an Activity for each screen. It seems too heavy weight, having to pass data around using intents seems like a real pain and each screen isn't a useful module by itself. As the "back" button doesn't always go back to the previous screen either, my menu layout doesn't seem to fit the activity model well.</p>

<p>At the moment, I'm representing each screen as an XML layout file and
I have one activity. I set the different buttons on each layout to call setContentView to update the screen the main activity is showing (e.g. the pause button changes the layout to the pause screen). The activity holds onto all the state needed (e.g. the current difficulty level and the game high score), which makes it easy to share data between screens. This seems roughly similar to the LunarLander sample, except I'm using multiple screens.</p>

<p>Does what I have at the moment sound OK or am I not doing things the typical Android way? Is there a class I can use (e.g. something like ViewFlipper) that could make my life easier?</p>

<p>By the way, my game screen is implemented as a SurfaceView that stores the game state. I need the state in this view to persist between calls to setContentView (e.g. to resume from paused). Is the right idea to create the game view when the activity starts, keep a reference to it and then use this reference with setContentView whenever I want the game screen to appear?</p>
