By Barry Burd

Every Android app has an AndroidManifest.xml file. The AndroidManifest.xml file provides information that a device needs in order to run the app. The AndroidManifest.xml file in this listing stores some options that you choose when you create a brand-new Android project. For example, the listing contains the package name, the minimum required SDK (the android:minSdkVersion attribute), and the target SDK (the android:targetSdkVersion attribute).

<?xml version="1.0" encoding="utf-8"?>
<manifest
  xmlns:android=
    "http://schemas.android.com/apk/res/android"
  package="com.example.myfirstandroidapp"
  android:versionCode="1"
  android:versionName="1.0" >
  <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />
  <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
      android:name=
        "com.example.myfirstandroidapp.MainActivity"
      android:label="@string/app_name" >
      <intent-filter>
        <action android:name=
          "android.intent.action.MAIN" />
        <category android:name=
          "android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
  </application>
</manifest>

For my money, the most important items in an AndroidManifest.xml file are the activity elements. The code in this listing has only one activity element. But a single Android app can have many activities, and each activity must have its own activity element in the app’s AndroidManifest.xml file.

An Android activity is one “screenful” of components. If you add an activity’s Java code to an Android application, you must also add an activity element to the application’s AndroidManifest.xml file. If you forget to add an activity element, you see an ActivityNotFoundException when you try to run the application.

Within an activity element, an intent-filter element describes the kinds of duties that this activity can fulfill for apps on the same device. To give you an idea, the action android.intent.action.MAIN indicates that this activity’s code can be the starting point of an app’s execution. And the category android.intent.category.LAUNCHER indicates that this activity’s icon can appear on the device’s Apps screen.