Let's learn how to add a new activity to your app.
In the Project pane, right-click the app folder and select New Activity Empty Activity.
In the following window, we fill out details for the new activity. Right now, all we need to do is set the name to SecondActivity. Notice that the Generate Layout File checkbox is checked.
Click Finish
This process does three things:
- Creates the class SecondActivity.java. If you look at this file, you might notice it has a similar structure to the MainActivity we already have.
- Creates the corresponding layout file activity_second.xml. The onCreate() method of SecondActivity.java sets this layout as the content view.
- Adds the required activity element in AndroidManifest.xml (we haven't learned about this yet)
We've successfully created a new activity. If you run the app, you'll find that all you see is MainActivity. We do not yet have a way to go from one Activity to another. Intents allow us to do this.