16

Could someone explain the following lines in the manifest -

    <activity
        android:name=".AboutUs"
        android:label="@string/app_name">
        <intent-filter >
            <action android:name="com.example.app1.ABOUT" />
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>

    </activity>    

How are the fields in activity and intent filter important and when are they used/referred ? Sorry, i tried to read the documentation but still couldnt figure much out.

Thank you

Ankit Rustagi
  • 5,539
  • 12
  • 39
  • 70
  • For the `DEFAULT` category you have this [answer][1]. [1]: http://stackoverflow.com/questions/5727828/what-is-the-purpose-of-android-intent-category-default – Gabriel Petrovay May 18 '13 at 13:50
  • check the documentation http://developer.android.com/guide/topics/manifest/manifest-intro.html – Raghunandan May 18 '13 at 13:54

3 Answers3

21
android:name=".AboutUs"

This is the name of your Activity class, the dot at the front is shorthand notation for your package. So this actually stands for com.your.package.name.AboutUs which means your java file that represents this Activity is called AboutUs.java

android:label="@string/app_name"

label is the string that gets shown in the launcher(if the activity is listed in the launcher) and at the top of the window when the activity is open.

<intent-filter > ... </intent-filter>

intent filter defines the Intents that your activity "listens for" in order to launch.

<action android:name="com.example.app1.ABOUT" />
<category android:name="android.intent.category.DEFAULT"/>

Action and category are both fields that get set on an Intent before it is "fired off" into the system. The system will then look for any activities that match both the action and category and if it finds one then it will launch that activity, or if it finds multiple it will show the user all of them and let them pick.

In your case your the action you are listening for com.example.app1.ABOUT is a custom action that is specific to your app, not one of the systems actions.

So here is what an intent that would start this particular activity might look like:

Intent i = new Intent();
i.setAction("com.example.app1.ABOUT");
i.addCategory("android.intent.category.DEFAULT");
startActivity(i);

Note that because you've created a custom action, this intent does not require access to your AboutUs.class so this intent could technically be fired from any app on the device and it would launch into your activity.

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • Great Answer ! Just what i needed. I have a doubt though. I usually start an activity the following way - `Intent i = new Intent("com.example.app1.ABOUT");` `startActivity(i);` This works fine, so does this mean that i can skip the setCategory part ? Thanks a lot ! – Ankit Rustagi May 18 '13 at 14:00
  • 1
    Yes, that will work fine, and yes you can skip the category since you are using `DEFAULT` – FoamyGuy May 18 '13 at 14:02
1

For the ACTION you have this answer and for the DEFAULT category you have this answer

Community
  • 1
  • 1
Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168
1

An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. To declare your activity, open your manifest file and add an element as a child of the element like your example.

  • The android:name attribute is the only required attribute—it specifies the class name of the activity.
  • The android:label attribute is a user-readable label for the application as a whole, and a default label for each of the application's components

An element can also specify various intent filters—using the element—in order to declare how other application components may activate it.

  • The element specifies that this is the "main" entry point to the application.
  • The element specifies that this activity should be listed in the system's application launcher (to allow users to launch this activity).

Please refer to the http://developer.android.com/guide/components/activities.html

rookiejava
  • 114
  • 4