Access an activity using implicit intents in Android

June 23, 2012

In Android operating system, intents are used for inter component communication. They acts as a messenger from one component to another. An intent may carry information such as target component name, filter action name, data , filter category , extras and flags. If an intent carry target component name, then that alone is used to identify a target component. Such a component is called explicit intent. If an intent does not carry target component name, then filter action name or data or filter category may be used to identify a target component. Such an intent is called implicit intent. The process of identifying a target component from action name, data and category is called intent resolution. In this article we will create an application which will make use an implicit intent for accessing a target activity component.

1. Create an Android Project namely “ImplitIntentDemo”

New Android Project

Figure 1 : New Android Project

2. Select android build target

Android Built Target

Figure 2: Android Built Target

3. Enter application details

Application Details

Figure 3: Application Details

4. res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>

    <string name="hello">Hello World, MainActivity!</string>
    <string name="app_name">ImplicitIntentDemo</string>
    <string name="btn_lbl">Open Second Activity</string>
    <string name="txt_second_activity">This is Second Activity</string>

  • Two new strings namely “btn_lbl” and “txt_second_activity” are added
  • The string “btn_lbl” is used in the layout file res/layout/main.xml
  • The string “txt_second_activity” is used in the layout file res/layout/second.xml

5. res/layout/second.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >

  • This file acts as a layout for our second activity
  • The second activity will contain a textview

6. src/in/wptrafficanalyzer/implicitintentdemo/

package in.wptrafficanalyzer.implicitintentdemo;

import android.os.Bundle;

public class SecondActivity extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
  • This is an activity file, which extends the class
  • We need to override the method onCreate(), which sets second.xml as the layout of this activity

7. AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

        android:label="@string/app_name" >
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

            android:label="@string/app_name" >
                <action android:name="in.wptrafficanalyzer.secondactivity" />
                <category android:name="android.intent.category.DEFAULT" />

  • The capabilities of the new activity “SecondActivity” is  specified in this file
  • The “name” attribute of the <activity> element specifies the component name which is used if this activity is called using an explicit intent
  • The capabilities of an activity is specified using the element <intent-filter>
  • The “name” attribute of the <action> element specifies an action name using which explicit intents can access this activity
  • The “name” attribute of the <category> element specifies a category name for this activity
  • Since we don’t need to sent any data to this activity, we are not specifying any <data> element

8. res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >

        android:text="@string/btn_lbl" />


  • This is the layout file for “MainAcitivity”
  • This activity will contain a button, clicking on which will open the “SecondActivity”

9. src/in/wptrafficanalyzer/implicitintentdemo/

package in.wptrafficanalyzer.implicitintentdemo;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        /** Defining a click event listener **/
        OnClickListener listener = new OnClickListener() {
            public void onClick(View v) {
                /** Creating an implicit intent using activities action name **/
                Intent intent = new Intent("in.wptrafficanalyzer.secondactivity");

                /** Accessing the intended activity */


        /** A reference to button object of the main.xml */
        Button btn = (Button) findViewById(;

        /** Setting and event listener for the button click */


  • ClickEvent listener is defined in this file to handle the button click
  • An implicit intent will be created  using action name of the intent filter

10. Application in execution

Main Activity

Figure 4 : Main Activity

Second Activity

Figure 2: Second Activity

  •  The second activity is called using implicit intent

11. Download

12. Reference

How to hire me?

I am George Mathew, working as software architect and Android app developer at

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to

My other blogs

Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :

Tags: , ,

One Response to Access an activity using implicit intents in Android

  1. tanuja on April 15, 2015 at 5:51 pm

    hello sir I am trying to run Location Rout Direction map v2 in eclipse kepler but it is not work kindly clear my queryand give me solution

Leave a Reply to tanuja Cancel reply

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

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner