AndroidManifest.xml file in android

The information of the package, along with the components of the application such as activities, services, broadcast receivers, content providers, etc, are included in the AndroidManifest.xml file in android.

There are also some other tasks performed by the AndroidManifest.xml file. These are:

  • To protect the application to access any protected parts by providing the permissions.
  • To declare the android API which will be used by the application.
  • To list the instrumentation classes which provide profiling and other pieces of information. However, just before the application is published, these pieces of information are removed.

For all the android applications, AndroidManifest.xml is the required XML file. It is located inside the root directory.

Simple AndroidManifest.xml file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.app1">
 
   <application
       android:allowBackup="true"
       android:icon="@mipmap/ic_launcher"
       android:label="@string/app_name"
       android:roundIcon="@mipmap/ic_launcher_round"
       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>
   </application>
 
</manifest>

Elements of the AndroidManifest.xml file:

All the elements of the AndroidManifest.xml file are listed and discussed below:

<manifest>:

Being the root element of the AndroidManifest.xml file, the manifest has the package attribute to describe the package name of the activity class.

<application>:

Being the subelement of the manifest, the application includes the namespace declaration and also contains several subelements to declare the application component such as activity. The icon, label, theme are the commonly used attributes of the application element.

android:icon :

The icon for all the android application components is represented by the icon attribute.

  • android:label: The label attribute works as the default label for all the application components.
  • android:theme: A common theme for all the android activities is represented by the theme attribute.

<activity>:

Being the subelement of application, activity represents an activity that must be defined in the AndroidManifest.xml file and also contains many attributes such as label, name, theme, launchMode etc.

  • android:label : A label i.e. displayed on the screen is represented by the label attribute.
  • android:name : A name for the activity class is represented by the name attribute. The name is a required attribute.

<intent-filter> :

Being the sub-element of activity, the intent-filter specifies the type of intent to which activity, service or broadcast receiver can respond to.

<action> :

The action attribute is used to add an action for the intent-filter. Thus, it is a must for the intent-filter to have at least one active element.

<category> :

The category attribute is used to add a category name to an intent-filter.

Content Protection by DMCA.com
Please Share