Lesson Tuesday

Every app must have an AndroidManifest.xml file. This file contains essential information about your app. The Android system must have this information before it can run the app's code correctly.

Manifest Responsibilities

Among other things, the manifest is responsible for the following:

  • Naming the Java package for the application.
  • Describing what components are present in the application, and under what conditions they may be launched.
  • Declaring which permissions the application requires from the phone and its user to interact with other applications and gather information.
  • Declaring permissions that others are required to have in order to interact with the application (For instance, an application that cannot function without access to the internet will declare in its manifest that it requires permission to access the internet.)
  • Declaring the minimum level of Android API the app requires.

In our MyRestaurants project, the Android Manifest currently looks something like this:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.epicodus.myrestaurants">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".RestaurantsActivity"></activity>
    </application>

</manifest>
  • The <manifest> and <application> xml tags are required in all Android manifests.

  • Each activity also contains an entry in the manifest.

  • The line <action android:name="android.intent.action.MAIN" /> denotes which activity will start by default when the app is launched. As we can see in our manifest above, the MainActivity is set to begin automatically when the app launches.

  • The line <category android:name="android.intent.category.LAUNCHER" /> denotes that this activity is the initial activity of a task, and is listed in the device's application launcher.

  • The <intent-filter> tag denotes the types of intents an activity may receive. We can see that the lines <action android:name="android.intent.action.MAIN" /> and <category android:name="android.intent.category.LAUNCHER" /> are in the <intent-filter> of the MainActivity. This is because the act of a device opening our application is actually an Intent from the Android system, and we therefore need to instruct our app to accept these intents. (We'll learn more about intent filters later on when we cover Implicit Intents!)

Additional Resources

For additional details, check out the App Manifest Guide in the Android Developers documentation.

Terminology


  • Android Manifest: A required XML file in any Android application that defines the name of the Java package, what components are present and how they may be launched, what permissions the app requires, and the minimum level Android API required.

Example


In our MyRestaurants project, the Android Manifest currently looks something like this:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.epicodus.myrestaurants">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".RestaurantsActivity"></activity>
    </application>

</manifest>

Additional Resources