Android development primer: Know the AndroidManifest.xml

This entry is part 12 of 50 in the series Android Development Primer

Enough programming. Let’s take a break and look into one of the vital components of any Android application, the AndroidManifest.xml file. Every Android application must have an AndroidManifest.xml file with that exact name, in its root directory. It provides the Android system important information about the application you are about to run in the device.

Navigate to <yourprojectname> -> AndroidManifest.xml. I will give you a brief overview of what purpose do the various sections of the manifest serve. Some of these might not be present in your manifest file. That is because components are added in the manifest file according to the needs of the developer. Nonetheless it will do you good to know about them.

  • package : This names the package your Android Application is in. You can change this at any time you want, but it will require further changes in each java file in your application.
  • versionCode : This is the version code of your application. This is useful when you are modifying you application and want to have a clean copy of the application as another version.
  • versionName : You can also name the version of your application. Change this to your liking.
  • minSdkVersion : While creating the project you must have selected a minimum API level. Devices having android versions below this API will not be able to run your application.
  • targetSdkVersion : While creating the project you must have selected a target API level. Devices having android versions below this API (and above the minimum API level) will be able to run your application, but you have indicated that this API is the one you are particularly targeting.
  • icon : This is the icon that will appear once the application has installed in your device. You can have an image in the drawable folder and make that you application icon.
  • label : This is the name of your application. Your application will be installed in the device or uploaded to the Android market by this name. The default value is @string/app_name. I will talk about what that is and how to change it in a later post.
  • theme : This is the basic theme of your application. It is the one you selected while first creating a project.
  • activity -> name : This is the name of you activity. There will be as many activity tags in your manifest, as there are activities in your application. Each activity must be declared in the manifest, failing which your application will crash as soon as you try to navigate to an undeclared activity.
  • activity -> screenOrientation : This indicates the orientation of the screen that the developer wants his application to have. It can have two possible values – portrait and landscape. For simplicity, portrait is vertical and landscape is horizontal. These are used when you do not want to auto-rotate the screen when the device is rotated. If the screenOrientation attribute is not specified, it indicates auto-rotation of the device screen is allowed.
  • intent-filter : If you have read my previous posts, I told you that an intent is used to push the current activity into the back stack and call upon another activity. The intent filter here acts in the same way. This, by default is present in only one activity MainActivity. That is because it is the activity which is first displayed when the application is launched. Since we are not switching from one activity to another here thus the Android system’s intent is used to do this.
  • receiver : Just like there are activities in the application, it can also contain broadcast receivers.  Each broadcast receiver must be declared in the manifest.
  • uses-permission : This is an interesting component. Your application might use some data or features from the user’s device that might/might not be acceptable to the user. In order to let the user know that some specific features and data are required in order for your application to work, uses-permission is used. This informs the user, at the time of installation of the application about these requirements. It is only after the user approves, that your application will be installed.
  • It also declares the permissions other applications need in order to communicate with your application.
  • The manifest also lists the library against which the application must be linked, if any.

So, you can see that the AndroidManifest.xml file serves the most important purpose of letting the Android system and the user know about what your application needs, what it does and other vital details.
Above are the most frequently seen/used components of the android manifest file. You might come across many more as you step into advanced Android Programming.

Series Navigation<< Android development primer: Creating Options Menu in Android – Part IVAndroid development primer: Creating Alert Dialogs in Android >>

Leave a Reply

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

*

* Copy This Password *

* Type Or Paste Password Here *

42,320 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>