6
Your Second Activity

In this chapter, you will add a second activity to GeoQuiz. An activity controls a screen of information, and this activity will add a second screen that offers users a chance to cheat on the current question by showing the answer. Figure 6.1 shows the new activity.

Figure 6.1  CheatActivity offers the chance to peek at the answer

CheatActivity offers the chance to peek at the answer

If users choose to view the answer and then return to the MainActivity and answer the question, they will get a new message, shown in Figure 6.2.

Figure 6.2  MainActivity knows if you’ve been cheating

MainActivity knows if you’ve been cheating

Why is this a good Android programming exercise? Because you will learn how to:

  • Create a new activity and a new layout for it.

  • Start an activity from another activity. Starting an activity means asking the OS to create an activity instance and call its onCreate(Bundle?) function.

  • Pass data between the parent (starting) activity and the child (started) activity.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.184.214