Comment on page
In the previous chapter, we mentioned how each activity consists of a layout file controlling the design and a class file to help with the logic behind all the different GUI elements. So far in our application we’ve only been working with one
Activityclass, but an application can have several!
Let’s see an example of this in action with Eatery.
MainActivity (1) and CampusMenuActivity (2)
The two different screens displayed here are each their own activities in the codebase. When the user clicks an Eatery card in
MainActivity, we say we launch the second activity. In the
onCreate()method of the second activity, we populate the
TextViewand wait times chart with the appropriate values. When the user clicks the back button in the second activity, then we say that the second activity has finished, and the display returns to
MainActivity(which is the last unfinished activity).
Returning to our project with the single
MainActivityclass, we can see that
AppCompatActivity, which is a built-in class that extends
This tells us that
MainActivityis of type
Activity, and so all of the
Activityclass methods become available for the programmer, including
setContentView()and the overridden method