0% found this document useful (0 votes)
12 views8 pages

Android Intents Explained: Types & Uses

Intents in Android are actions that facilitate communication between components, with three fundamental use cases: starting an activity, starting a service, and delivering a broadcast. Intents consist of primary information like ACTION and DATA, along with secondary attributes such as CATEGORY, EXTRAS, and FLAGS. There are two types of intents: implicit intents, which do not specify the component, and explicit intents, which directly reference the target activity.

Uploaded by

trailacc94
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views8 pages

Android Intents Explained: Types & Uses

Intents in Android are actions that facilitate communication between components, with three fundamental use cases: starting an activity, starting a service, and delivering a broadcast. Intents consist of primary information like ACTION and DATA, along with secondary attributes such as CATEGORY, EXTRAS, and FLAGS. There are two types of intents: implicit intents, which do not specify the component, and explicit intents, which directly reference the target activity.

Uploaded by

trailacc94
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Intents

• At the simplest level, an intent is an action that you can tell Android to
perform (or invoke). The action Android invokes depends on what is
registered for that action.
• Intents facilitate communication b/w components in several ways.
• 3 fundamental use cases
• Starting an activity:- an activity represents single screen in an [Link] start a
new instance of an activity ,pass an intent to startActivity(). To receive a result
from an activity when finishes, call startActivityForResult()
• Starting a service:- a service is a component that performs operations in the
background without a user [Link] start a service to perform a one-time
operation, pass an intent to startService()
• Delivering a broadcast:-broadcast is a message that any app can [Link]
deliver a broadcast to other apps,pass an intent to sendBroadcast() or
sendOrderedBroadcast()
Available Intents in Android
The set of available applications could include
• A browser application to open a browser window
• An application to call a telephone number
• An application to present a phone dialer so the user can enter the
numbers and make a call through the UI
• A mapping application to show the map of the world at a given
latitude and longitude coordinate
• public static void invokeWebSearch(Activity activity)
{
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
[Link]([Link]("[Link]
[Link](intent);
}
Intent structure
• Primary pieces of information in an intent
• ACTION:- The general action to be
performed.ACTION_VIEW,ACTION_EDIT,ACTION_MAIN
• DATA :- The data to operate on such as person record in the contact
database ,expressed as uri
Examples of action/data pairs
• ACTION_VIEW content://contacts/people/1 →display information
about person whose ID=1
• ACTION_DIAL content://contacts/people/1 →display phone dialler
with person filled in
• ACTION_VIEW [Link] ,ACTION_DIAL [Link] phone
dialler with given number filled in
• ACTION_EDIT content://contacts/people/1 →EDIT information about
person whose ID=1
SECONDARY ATTRIBUTES OF INTENTS
▪ CATEGORY:-gives additional information about kind of component that
should handle the intent. addCategory() places a category in an intent object,
removeCategory() deletes a category previously added, getCategories() gets
the set of all categories currently in the object .
▪ For example, CATEGORY_LAUNCHER means it should appear in the
Launcher as a top-level application, while CATEGORY_ALTERNATIVE
means it should be included in a list of alternative actions the user can
perform on a piece of data.
▪ EXTRAS: This is a Bundle of any additional information. Used to provide
extended information to the [Link] be set and read using putExtras()
and getExtras()
▪ For example, if we have a action to send an e-mail message, we could also
include extra pieces of data here to supply a subject, body, etc.
▪ FLAGS: optional part of intent object that instruct android system how to
launch an activity and how to treat it after it is launched
▪ FLAG_ACTIVITY_CLEAR_TASK, FLAG_ACTIVITY_NEW_TASK
Types of intents

▪ Implicit intents: Do not specify the android components which


should be called .
▪ Only specifies action to be performed. A Uri can be used with
implicit intent to specify the datatype
▪ Intent intent=new Intent(ACTION_VIEW,[Link]([Link]
▪ Explicit intent: Use explicit intents when you know exactly
which activity can handle the request.
▪ Explicit intents are used in applications wherein one activity can
switch to other activity .
▪ Typically used for application- internal- messages Such as an
activity starting a subroutine service or launching a sister activity
▪ Intent i=newIntent([Link],[Link])
startActivity(i);

You might also like