♪ (electronic music) ♪ Now in this particular application I'm going to create a <i>MainActivity</i> and inside that <i>MainActivity</i>
I will create three buttons. First button will open up my browser, second button will open up my dialer, third button will open up my map. So, all these three tasks will open up my three different applications. So that's the reason
we use implicit intent-- to open up the activity
of some different applications, or the system apps which are already
installed inside your device. So, I will create a title, and call it... <i>Implicit Intent</i>... <i>match_parent</i>-- just not making <i>match_parent</i>-- and change the size to 36 and call it... let's just call the ID be... <i>title</i> and text to be <i>Implicit intent.</i> And then create three buttons. First button will be <i>Open Web...</i> and <i>match_parent.</i> Second will be... <i>Open Call,</i> and <i>match_parent.</i> For all the buttons
I'm going to give the ID, let's say, <i>b1</i>... <i>b2.</i> And third button... will have <i>b3</i>... and we will call it <i>Open Map,</i> and <i>match_parent.</i> Now, in each of these buttons I need an <i>onClick</i> attribute. So... I'll go inside the XML file
and I will type <i>onClick</i> attribute and let's just say <i>doSomething.</i> Now, I could have defined
a different <i>onClick</i> attribute in each of these buttons, but in this case, I'm going to use
the same attribute. If I'm doing that then while I define this <i>doSomething</i> inside my Java class, and for that what I need is <i>Alt + Enter,</i> just select on the text and <i>Alt + Enter</i> and it will automatically get created. Now, for all these three buttons,
whenever I click, it will come to the same method. So, I need to distinguish
between all those methods. How do I do that? For that I need to create <i>switch,</i> or you could have used
[if false condition] too. <i>view.getId</i> At any one point of time
you will be clicking only one button, so I can use <i>switch</i>
and start making my <i>cases.</i> Pick <i>R.id.b1</i> so whenever somebody clicks on <i>b1,</i> because that's my first button, because that's the ID
of my first button. Whenever somebody
clicks on my first button, I will get the code inside this <i>case.</i> And if somebody clicks on button two, I will make another case for that and I will put the code
inside the second case. And similarly,
I will put the third case for <i>b3.</i> Now, as I'm using implicit intent, this time around I don't know
the name of my activity. So I will create the <i>Intent</i> object and in that <i>Intent</i> object, first thing will be my action. So action will be <i>Intent.</i>-- let's say, I want to open up a webpage-- so <i>ACTION_VIEW,</i> it's a generalized action. Now, this generalized action
will depend upon the type of URI you are parsing, so it can be used for your dialer also, it can be used for your map also, so, you don't have to remember
all the actions together. All you need to know
is what kind of URI you are parsing. So, let's say, in this particular example, I'm parsing <i>Uri.parse</i> ("http://www.google.com") and then <i>start</i> that triggers your intent. So you see, now, whenever somebody clicks
on your first button, it goes to your action that is <i>ActionView.</i> <i>ActionView</i> means open up
the appropriate activity or look out for appropriate activity who can handle this particular request,
that is <i>http</i> and <i>http</i> is your data scheme here. Similarly, let's say, I want to... open up the dialer now, whenever somebody clicks
on the second button. For that, <i>Intent.Action_view.</i> I could have used <i>Action_dial</i> too because I know
this is the specific action for this particular action
which I want to perform, but if you don't know,
you could always use <i>Action_view.</i> If you don't know,
you can always use <i>Action_view</i> and here <i>Uri.parse...</i> this time you won't do <i>http,</i> this time you will do <i>"tell:" ,</i> this time the data scheme will change
and provide a number. And-- I need to change the variable name because <i>i1</i> has already been used and inside this code
I will change the name-- and now you have to trigger <i>i2.</i> So now my dialer will open up. In the same way,
I can look out for my map also. But this time <i>Intent i3 = new Intent</i> and again, I can use the same <i>ACTION_VIEW</i> but again, what will be changed the data URI, and this time for opening up a map, the data scheme is <i>geo</i> and I need to parse
longitude and latitude. So let's just check out
the longitude and latitude for our... India. "India longitude and latitude". So, I will just copy
this longitude and latitude and paste them here, put a comma... paste it and close it and trigger your intent, <i>startActivity(i3)</i> and that's all. That's all you need
to invoke the activities from your different applications. Now let's just see
how this really looks like by running this in an emulator. My application is up running
in my emulator so let's just see how exactly it runs. Let's just click on
my first button <i>Open Web.</i> It should open up my web browser. Now, you can see here, my Android runtime
provided me with an app chooser because right now
it sees that there are two applications which can actually handle my http request, that is a Chrome browser and there is a WebView Browser
of my Android itself. So I get to choose which browser
I want to use to open up my application, or open up my web link. So I will use Chrome. Accept it. I don't need to sign. And there you go. As you can see, Google is up now, right? Google website is up now. If you change the website name, that website will be opening up here. Now when you press back, in the back stack
your application was there, that's the reason your application
will be coming back. Now when you click on <i>Call,</i> your call... that number which you have
just parsed there, is now there with the dialer. Now you can make a call. You click on this
and you will be able to make a call in a real device. In an emulator, no,
you can't make a call here. I mean, it will give you a feel
like you are making a call but it's not really making a call otherwise people will stop buying phones. (beep) But in a real device
it will be making a call. Last, there is <i>Open Map.</i> Just click on <i>Open Map</i> and it will transfer you
to a map application. As you can see inside my device
there is a map application. So, whatever the longitude and latitude
you have parsed there, now it has taken you there only. Now it is India but it's pretty zoomed in so let me just zoom out a little bit. Maybe you will be able to... Yeah, there you go. So this is India. So, that was the example or that was the practical demo
for implicit intent. Thank you. ♪ (electronic music) ♪