Home > Android > android intent tutorial

android intent tutorial

Today i am going to talk about something called intent. To get more in depth knowledge about android you should have basic understanding about intent.

Intent comes with your intention. It’s pretty interesting after you really understand what this is for.

Android uses two kinds of intent:

  1. Implicit Intent
  2. Explicit Intent

Let’s see a real world example, say you want some information about intent but you don’t know where to get it but you only know you want to see information about intent. So what do you do? You will be open up your browser -> go to google -> and enter something about intent and search

Now what google will do, it will search its entire database and try to match with those that best describe your entered keywords and return it to you.

What if you knew that in my blog there is a post about intent that badly describe about intent and still you wanna see that, then you will probably enter my blog address in your browser url instead of going to google. Though it’s not a bad idea to go to google for various type of information. At least I would do that. 🙂

In first case what did you do?

You did give some data to google and google fired something at you when it found something using that data.

This will be implicit since you didn’t know where in the world has a server which reside the appropriate data in terms your given data.

In the second case you did know explicitly where can you find your data, so you explicitly told your browser to take you there.

And that is also the case for android too.

Intent intent=new Intent(Intent.ACTION_PICK,
Uri.parse("content://contacts/"));
startActivityForResult(intent,PICK_CONTACT);

is used with implicit intent. As you can see here, in creating new intent we need an action and the data that action will be performed on. Now startActivityForResult will launch the activity that uses “content://contacts/” kind of data. As for the action though you don’t know if they don’t tell you what kind of action is permitted on that application’s activity but we know in the case we are using now because Intent.ACTION_PICK is supported by android’s own contact application so this intent will launch android’s native contact application where we can pick a contact that we choose and return with the result in your activity. As with previous example here you only knew what kind of data you needed what you wanna do with that data, now android will lookup for an appropriate application that uses this kind of data and also permit the kind of action you are requesting since some application’s data will not be available to others to use. If any appropriate application is found android will start that activity and show it to you to do your work.

As of explicit:


Intent intent=new Intent(PageOne.this,PageTwo.class);
startActivity(intent);

You can easily guess that in here I’m in page one and I want to go another activity that is page two.

Here I explicitly told which activity I want to start.

Notice that I used startActivityForResult for the first one and startActivity for the second one, this may confused you a little bit, I will explain it to you later.

I think that explain not much but little bit about intent.

It will be more clear if you see some example application.

Using Implicit Intent:  ContactPicker

Using Explicit Intent: ReportGenerator

or you can check it from here:
svn checkout http://reportgenerator.googlecode.com/svn/trunk/

this entire application uses explicit intent to go from one page to another.

Thank you for checking by and  if you have any question or suggestion please do comment. I appreciate that very much.

HAVE A GOOD PROGRAMMING

Advertisements
Categories: Android
  1. July 7, 2013 at 7:51 am

    Hi there indeed it very good post on intent you also check this one at
    Implicit Intent
    Explicit Intent

  2. September 12, 2014 at 7:49 pm

    This design is steller! You certainly know how to keep
    a reader entertained. Between your wit and your videos, I was almost moved
    to start my own blog (well,almost…HaHa!) Wonderful job.
    I really enjoyed what yyou had to say, and more than that, how you presented it.

    Too cool!

  1. No trackbacks yet.

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: