The Android Manifest File

Every Android app you create needs a Manifest file. You will find it in the manifests folder:

Android Studio showing  a manifest file in the explorer window

The Manifest file provides information about your app, and is in XML format. Among other things, the manifest file contains the name of your Java package, and lists components like Activities, services, content providers, and lots more. If your app needs certain permissions, then they'll be listed here (you'll see how to add permissions much later in the course). In short, the Manifest file is a crucial part of your Android app.

What we'll do is to add a line to the Manifest file. The effect of this will be to add a back arrow to the Action Bar at the top of the app.

Double click your AndroidManifest.xml file in the Explorer on the left. This will open it up in the coding window. It will look like this in earlier versions of Android Studio:

The Android Manifest file in XML

In later versions, the SecondActivity line will be somewhere in the middle:

The Android Manifest file in Android Studio 3

If you examine the code, you'll see that there are two ACTIVITY tags. The first one has the android name .MainActivity. The second one has the name .SecondActivity. It's this second one we need to amend. Change it to this:

<activity android:name=".SecondActivity"



Take particular note of where all the angle brackets are. Your code should look like this:

The Manifest file with a second Activity added

Or this:

Changes made to the Android Manifest file

By setting the parent activity name as MainActivity you'll get the back arrow in the Action Bar at the top of your screen.

Try it out. Run your app again. Click the button to launch the second activity. You should see this as the second screen:

Emulator showing a second Activity running

Notice the white arrow pointing to the left at the top of the screen. Click or press the arrow and it will take you back to the main activity.

While we're discussing activities and intents, what we'll do now is to send some information from the first activity to the second activity. This information will be displayed in the Text View on the second activity.

Back to the Android Contents Page