Sunday 11 November 2012

Handling the activity not Launched Problem

While  creating the application we add new Activities and corresponding to that we have to add the reference to the activity in the AndroidManifest.xml file but there is another important step that needs to be taken into account in order to launch or start a new activity on the emulator.

This deals with adding the Intent - which does the binding of the various components and the functionalties  related to them at the run time.  This can be done between the components of the same or different package.

So we need to write the following code in the Manifest file :
<application
.............
.............
<activity
.............
.............

 <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
</activity>
</application>

Without the above line the application does not gets launched on the emulator.

Now let's understand what the above lines mean in effect:


  • Intent-filter - By this we implicitly define that to which intent the component is to be bound at the run time and we filter out the rest undesirable intents.
    • category android:name="android.intent.category.LAUNCHER" : we specify that we want to be able to launch this specific activity.

No comments:

Post a Comment