Intents in Android
By:
Amal AL Jarousha
What is Intent
• intent is a messaging object used to request
an action from another app component
• Or through activities in the same application
• Intent facilate communication between
different components
There are two different types of intent
• Explicit
• Implicit
Intents are used to:
• start an activity
• start a service(open email, web browser
calling)
• pass data in same application or different
application.
• also Intent is use for Broadcasting message
like if we have low battery in your mobile, and
you opened any application , it will appear a
message that you have low battery
• this communication between the OS and
applications is produce by Intent
What do I do with intents?
• tell what action you want to perform without
worrying about who can perform it
• get notifications when something happen in
your system
who do you call ?
• Activities
An Activity represents a single screen in an app. You can start a new
instance of an Activity by passing an Intent to startActivity().
The Intent describes the activity to start and carries any necessary
data.
• Services
A Service is a component that performs operations in the background
without a user interface.
• Broadcast Receiver
A broadcast is a message that any app can receive. The system
delivers various broadcasts for system events, such as when the
system boots up or the device starts charging
you can call any 1 of them using Intent Object
The component you call doesn't need to be actively running
• The Package Manager in android is the
component who is responsible for handling
intents
Explicit Intent
communicate between two different activities in
the same application
Implicit Intent
communicate between two different activities in
the different application.
like if you communicate between the application
and email applications, or social media
applications
For Example:
If I need email functionality in my app and
I don't want to waste my time in building email
functionality.
I will use an activity for sending email
so I can define the function I need and let
android call the right Activity for my task
The primary information contained in an Intent
• Component name
The name of the component to start.
• Action:
define what you want to do (ex: place a phone call)
• Data:
what type of data you want to work with (ex: url, images)
• Extras:
what Additional information you need to provide (key/value pairs)
(ex: phone number of the person to call)
• Categories
create groups of components to handle the intent
give additional information along the action
(ex: place the Activity A in the launcher)