Android Manifest file

Every Android application must have a manifest file called AndroidManifest.xml file that describes the application.

A sample manifest

<?xml version=“1.0” encoding=“utf-8”?>
<manifest xmlns:android=“http://schemas.android.com/apk/res/android”
package=“com.example.firstapp” >
<application
android:allowBackup=“true”
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/AppTheme” >
<activity
android:name=“com.example.firstapp.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>

A manifest file is an XML document with manifest as the root element. The package attribute of the manifest element specifies a unique identifier for the application. Android tools will also use this information to generate appropriate Java classes that are used from the Java source you write.

Under <manifest> is an application element that describes the application. Among others, it contains one or more activity elements that describe activities in your app. An application typically has a main activity that serves as the entry point to the application.

The name attribute of an activity element specifies an activity class. It can be a fully qualified name or just the class name. If it is the latter, the class is assumed to be in the package specified by the package attribute of the manifest element. In other words, the

name attribute of the above activity element can be written as one of the following:

android:name=“MainActivity”
android:name=”.MainActivity”

You can reference a resource from your manifest file (and other XML files in the project)

using this format:

@resourceType/name

For example, these are some of the attributes of the application element in :

android:icon=”@drawable/ic_launcher”

android:label=”@string/app_name”

android:theme=”@style/AppTheme”

The first attribute, android:icon, refers to a drawable named ic_launcher. If you browse the project in Android Studio, you can find an ic_launcher.png file under res/drawable.

The second attribute, android:label, refers to a string resource called app_name. All string resources are located in the strings.xml file under res/values.

Finally, the third attribute, android:theme, references a style named AppTheme. All styles are defined in the styles.xml file under res/values.

 

Leave a Reply

Your email address will not be published. Required fields are marked *