Programming and Personal Development

7 things you should know about Android Manifest xml file

The android application is made up of a number of loosely coupled components  viz.  activities, services, content providers and broadcast receivers.  The androidmanifest.xml file  at the root of   application folder, is the glue that listsAndroid manifest these individual components together to form one cohesive application.  Lets take a quick look at main elements inside the manifest file.

  1. The main element is not surprisingly the manifest element.  It has attributes to specify :
    • Android namespace schema url ( “http://schemas.android.com/apk/res/android”)
    • Base package name for the android application. This serves two purposes:
      • Uniquely identifies the application on a device.   Your website url would be a good choice. eg:  yourwebsite.com.package.suffix
      • Acts as a shortcut for dot (“.”) that can used to specify  the class names elsewhere in the manifest file. For eg, “.MainActivity” instead of com.example.MainActivity in the example shown here.
    • Android manifest version code is an integer that is used to identify the version of your application. Newer versions are expected to have a higher version code than the older ones and is  used in deciding whether to update your application with a new version.
  1. The minsdkversion element indicates the minimum api level supported by your android application. For example if  you are using the apis  that are only supported  in the latest android version ( say icecream sandwitch) , youandroid manifest example specify the minsdkversion as “15″. This prevents your application from being installed on a old device that doesn’t support the latest apis. You can also explicitly specify the targetsdkversion.
  2. The <application> is the main element in the manifest file that describes your application components and their intents. Among its many attributes in the android manifest file is the debuggable attribute which needs to be true if you want to support debugging the application on an actual device rather than in a emulator.
  3. Activities are  the UI screens through which the user interacts with your application and intents are abstractions describing the operation that can be performed on the android components. You can use the android manifest activity element to list all the activities in your application along with their  intents.  In this example, we specify the com.example.MainActivity  as the MAIN  intent  for the application and assign it a LAUNCHER category which tells the android system to launch this screen when the user open your application for the first time.
  4. Android manifest service are long running background task that do not have any UI.  They are useful for keeping something running regardless of whether its being rendered on the screen. The typical example is a keeping the music running in the background while you check the  weather using the weather app. The <service> element is used to list the services in your application.
  5. Broadcast receivers are pieces of logic that respond to various  events/intent that occur in the system.  For example,  when an SMS is received, an event is  broadcast by the system. All the receivers receive the event, but only the receiver responsible for handling the SMS actually does something with it. You can use the <receiver>element  to specify the list of  receivers in your application.
  6. <provider> element is  used for specifying the content providers.  The android manifest provider elements refer to components that provide a seamless interface for creating and accessing shared  data.  For example, the android system shares the contact information as a content provider that you can then make use of in your application using the content provider apis.
In addition to the above mentioned elements, the android manifest file also specifies the permissions needed by application, the libraries it uses and so on.

 

 

Web Analytics