Explicit Intent

Now, lets see how the components in android communicate.

Communication between the three core components in android-activity, service and broadcast receiver is made possible using intents. Intents can be said as messages passed between these components. An Intent object is a bundle of information containing information such as the action to be performed, data on which the action is to be performed etc.

Intents are of two types: Explicit intents and Implicit intents

Here , in this post, I’m discussing about Explicit Intent.

Explicit intents: They specify the target component by its name.That is, they explicitly specify the target component which needs to respond to it.

Here is how it is done:

Intent intent=new Intent(source.this,destination.class);


Intent intent=new Intent();

Lets see what an explicit intent is and how it works through a simple example.

Code for the Source activity :

public class Source extends Activity {
/** Called when the activity is first created. */
Button dest;
public void onCreate(Bundle savedInstanceState) {
dest.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
 Intent intent=new Intent(Source.this,Destination.class);

The XML code for main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" >
android:text="Click to go to destination"
android:textSize="20dip" />

This is how the UI looks:

Code for the Destination activity:

public class Destination extends Activity{
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub

XML code for maindest.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:text="Welcome to Destination"
android:textColor="#0000ff" />

The Output When the Button on the Source UI is clicked :

Hope this helped you in understanding an Intent and how it works.


, , , , , , ,

  1. #1 by Ida on October 7, 2012 - 9:32 pm

    Excellent tutorial. If there is one thing that is difficult to find good information on as a beginner, it’s how buttons work and how to make the click of a button lead to a new page. Thank you!

  2. #2 by meenu on October 19, 2012 - 2:23 pm


  3. #3 by meenu on October 19, 2012 - 8:21 pm

    one more thing,
    even though this is just an example of intent, you should have used finish method( i am not sure,as i am a beginner).Though app worked properly i faced problems in closing the destination activity.So it would have been complete if you added methods to close the activities as well…

  4. #4 by Sanketh Salian on December 24, 2013 - 11:22 pm

    wht do i do if i need mutiple button on the same page which leads to different page

  5. #5 by Priyanka on February 22, 2015 - 4:41 pm

    Thank you so much..it heped me…

  1. How to: What is Intent in Android? | SevenNet
  2. Answer: What is Intent in Android? #answer #it #programming | IT Info
  3. What is Intent in Android? - DexPage

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: