Skip to content

Using Android Intents Tutorial

Categorically Speaking

We have added each of our activities to the Android Manifest. At this point I want to look at what we currently have in the manifest.

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.learnandroid.intents"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk android:minSdkVersion="3" />
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".UsingIntentsActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="GetName"></activity>
        <activity android:name="UriActivity"></activity>
    </application>
 
</manifest>

You’ll notice two of our activities are simple tags with just a name.

        <activity android:name="GetName"></activity>
        <activity android:name="UriActivity"></activity>

But one of our activities has a section named intent-filter

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

We saw actions in the last section (and this is how you tell android what actions your activity can perform), but the category is new. This combination of the action “android.intent.action.MAIN” and the category “android.intent.category.LAUNCHER” tells android that this is the main activity that should be launched when the user touches the application icon in the launcher. We can use the action and category to limit what is affected by our intent. So let’s add a category and action to our other two activities now.

We can use whatever we want for our action and our category. The Android developers recommend that if you use your own action or your own category that you prefix it with your package name, to prevent accidentally using the same action as another application on the phone. Here is our Manifest file now.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.learnandroid.intents"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk android:minSdkVersion="3" />
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".UsingIntentsActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="GetName" android:label="The Activity You Know">
            <intent-filter >
                <action android:name="com.learnandroid.intents.VIEW_SAMPLE_CODE" />
                <category android:name="com.learnandroid.intents.SAMPLE_CODE"/>                
            </intent-filter>
        </activity>
        <activity android:name="UriActivity" android:label="The URI You Know">
            <intent-filter >
                <action android:name="com.learnandroid.intents.VIEW_SAMPLE_CODE" />
                <category android:name="com.learnandroid.intents.SAMPLE_CODE"/>                
            </intent-filter>
        </activity>
    </application>
 
</manifest>

You might have noticed that I also added labels for our Activities. We’re going to use the actions, categories, and labels in the Android Manifest to automatically update the list in our main activity, replacing the hard coded array we have been using.

Next: A Little Manifest Destiny

{ 6 } Comments

  1. shub | May 30, 2012 at 5:07 pm | Permalink

    i am new to android can you please explain what is onclicklistner (not what is does) and why we use View.onclicklistner and what is view there

  2. krishna | August 10, 2012 at 2:19 am | Permalink

    very useful, thaks..

  3. dinesh | February 10, 2014 at 3:24 am | Permalink

    wow…amazing…you give simple and easy look to android layout…..

    thank you very much

  4. fixit | April 11, 2014 at 11:56 am | Permalink

    great post, very useful for beginers

  5. Alex Butler | September 27, 2014 at 3:59 am | Permalink

    Will you accept guest post content?

  6. Sheridan | September 27, 2014 at 7:28 am | Permalink

    Sure, I would be willing to accept a guest post. Basically, my criteria would be that I should be able to open Eclipse, go through your tutorial step by step, and have it work without needed to figure out any extra stuff.

    Basically, I started this website with a friend (he wrote the lots of lists post). I was very gung ho about it… and then I found myself going through a divorce. I’ve kicked around the idea of starting to do tutorials again, and would be glad to have new content on here.

Post a Comment

Your email is never published nor shared. Required fields are marked *