Passing Data Between Activities

Now that you have a MainActivity and a CheatActivity, you can think about passing data between them. Figure 6.8 shows what data you will pass between the two activities.

Figure 6.8  The conversation between MainActivity and CheatActivity

The conversation between MainActivity and CheatActivity

The MainActivity will inform the CheatActivity of the answer to the current question when the CheatActivity is started.

When the user presses the Back button to return to the MainActivity, the CheatActivity will be destroyed. In its last gasp, it will send data to the MainActivity about whether the user cheated.

You will start with passing data from MainActivity ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.