2. Explicit Intents
Intents, Android Basic Building blocks, Activities, Services, Broadcast Receivers, Intents, Types
of Intents, Explicit Intents, Implicit Intents, Basic Example of Explicit Intents in Android
3. Intents
• Intent means many different meaning in different situations.
• So in this lecture I will show, What intents are, what they do, and how they
do.
4. There’re four building blocks in Android
• Activities
• Services.
• Broadcast Receivers.
• Intent.
5. Activities
• Something with which user interacts, something the user sees
on the screen.
Farrukh Ehsan – Superior University Lahore -
farrukh.ehsan@superior.edu.pk
6. Services
Something that runs in the background, but it runs on the main thread.
These are used to perform the long tasks, like downloading a file,
connecting to a mail service, connecting to a server, uploading a file to a
drop box and stuff like that.
All these thing happens in services.
User can’t see them, but they started by activities and such operations run
independently. Even if your activity is off your services may run in the
background.
7. Broadcast Receivers
These are functions who sleeps all the time, but when suddenly something
happens, they wake up and they do something.
For example if your battery gets low, and you have broadcast receiver
inside your app who wakes up and shut down all the downloads.
So that’s what broadcast receivers do. These are a kind a alarms that you
want ring when a specific event triggered.
8. Intent
• It is a kind of messenger that response to messages.
9. What an intent does?
• It is used to start a new activity from where ever you are. It is like going to a different page
in html from one page.
• If you want to download something your download services begin in the background in
case you’re downloading a big file, or you want to play music in the background, so intents
are used to start all these services.
• The third thing that intents are used register the broadcast receivers.
• Intents are also used to tell the system, which is the entry point of your application inside
of your application, and which activity should appear in launcher screen, or inside the list
of application installed on your android OS.
12. Implicit Intents
• Implicit intents, when you don’t know who to call.
• You know you need to send a SMS, or you need to send an
Email, when know the functionality but you don’t know, who is
going to do that function for you, that’s when an intent will
become implicit intent.
18. Implicit Intents
• Implicit Intents just define the functionality and let the Android OS to decide the right
activity for that functionality.
• With the implicit intents, you just tell the action you want to perform without worrying
about who will perform that action.
19. • You get a notification when something happens in your phone.
• For example before making a call, your airplane mode is ON or your battery level gets low.
20. • So whenever there is an event and an intent is created out of that event, it
will be supplied to everybody.
• Suppose you’ve a broadcast receiver, who is actively listening to such
events, then that broadcast receiver is going to be connected.
• There are hundreds of event in Android device that converted into an
intent object, and that intent broadcast to everybody in the Android OS.
21. There are four pieces of an Intent
1. Action
2. Data
3. Extras
4. Categories
22. Action
• Here you define, what you want to do. For example you want to
place a phone call, you want to send an SMS etc.
23. Data
• What type of the data you want to work with.
• For example URI, images or whatever type of data you are
working with.
•
24. Extras
• What additional information you want to provide.
• For example, you want to application to place a phone call, but who you
want to call, what is phone number of that particular person you want to
call.
• In the extra you provide additional information needed to perform the
task.
25. Categories
• Categories are nothing more than group of components which are used to
handle the intents.
• For example if you remember from the first lecture, in all your activities
inside your application, you have something called category launcher, that
how your activity appears in the list of apps in the launcher.
26. Who do you call?
• Basically there are three things that works with intent.
• You want to call somebody either it can be activities, or it can services or
it can broadcast receivers.
• Now remember activities and services comes one category, and
broadcast receivers come under separate category.
• You can call any one of them using an intent object, there are different
methods are used to start these three things such as start activity.
27. Android Package Manager
• It is the part of Android OS, who is responsible for the handling the intents
in the Android.
• When a Package Manager receives an intent request, its going to check
which applications are running, which are applications are nothing
running.
• Android Package Manager is responsible for deciding which component is
best suited to handle your intent.
28. What is an Intent Filter?
• Whenever you want to handle the implicit intent you have to declare the
intent filters.
• Intent filters are simply advertisers. They say for action, category, data a
particular activity, service or broadcast receiver can handle.
29. Intent Filter - Example 1/2
• For example you have your activity A, and you want to send an Email.
• So what you are going to do? You are going to create an intent that has some
action, category and data.
• On the other hand you have your email activity B, where it define an intent
filter to define what type of data, action, and category it can handle.
• Now your Package Manager accept the intent which is sent, it compares the
action, data and category requested by the first activity with the action, data and
category define inside the intent filter of the other activity B.
• And if they match, then that activity B is called. That’s how your email activity
will be called through implicit intent.
31. You send an intent that intent gets compared with the intent filter
on the receiving side. If it matches then that activity, service or
broadcast receiver gets called, otherwise nothing will happen.
32. • So an intent filter describe what ACTION, DATA, and
CATEGORIES that component can handle.
• Mostly intent filter defined inside the manifest file, but may also
be dynamically register in the code.
• Next you define what intents can be handled by that component.
• In the next step you write that code which you want to be
executed when an intent is called.
33. Package Manager with activities and Services
• When you install an activity, you are going to define an intent filter to the
Android Package Manager, it will read your intent filter, and after checking
it will define what ACTION, DATA and CATEGORIES your activity can
handle.
• This happens for every application you install on your Android OS.
• How many activities or services an app have?, what intents can be handled
by each Activity or Service, this data is handled by the Android Package
Manager.
34.
35. Intent resolution
• The whole process of receiving an intent request and then
starting the suited activity or service for that intent is called
intent resolution.
• This complete process is monitor and managed by the Android
Package Manager.
• This process is only used for Activities and Services.
36. Quiz_02:
Q_01
What the purpose for using explicit intent explain with example?
Q_02
Why implicit intent different from explicit intent explain with
example?