0% found this document useful (0 votes)
42 views12 pages

Lecture06 Intents

An intent is an abstract description of an operation that can be performed. There are three main uses of intents: starting activities, starting services, and delivering broadcasts. An intent specifies the component to start and carries any necessary data. Explicit intents specify the exact component class, while implicit intents declare a general action and allow other apps to handle it if they match the intent filter. The primary pieces of information in an intent are the action and data. Common actions include ACTION_VIEW, ACTION_SEND, and custom actions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views12 pages

Lecture06 Intents

An intent is an abstract description of an operation that can be performed. There are three main uses of intents: starting activities, starting services, and delivering broadcasts. An intent specifies the component to start and carries any necessary data. Explicit intents specify the exact component class, while implicit intents declare a general action and allow other apps to handle it if they match the intent filter. The primary pieces of information in an intent are the action and data. Common actions include ACTION_VIEW, ACTION_SEND, and custom actions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Intent

• An intent is an abstract description of an


operation to be performed.
• An Intent is a messaging object you can use to
request an action from another app
component.
Intent
• Although intents facilitate communication
between components in several ways, there
are three fundamental use cases:
– Starting an activity
– Starting a service
– Delivering a broadcast
Intent: Starting an Activity
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.

If you want to receive a result from the activity


when it finishes, call startActivityForResult(). Your
activity receives the result as a separate Intent
object in your activity's onActivityResult() callback.
Intent: Starting a Service
• A Service is a component that performs
operations in the background without a user
interface.
• You can start a service to perform a one-time
operation (such as downloading a file) by
passing an Intent to startService().
• The Intent describes the service to start and
carries any necessary data.
Intent: Delivering a Broadcast
• 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 deliver a broadcast to other apps by
passing an Intent to sendBroadcast() or
sendOrderedBroadcast().
Intent Types
• Explicit intents
• Implicit intents
Intent Types: Explicit Intents
• Explicit intents specify which application will satisfy
the intent, by supplying either the target app's
package name or a fully-qualified component class
name.
• You'll typically use an explicit intent to start a
component in your own app, because you know the
class name of the activity or service you want to
start.
• For example, you might start a new activity within
your app in response to a user action, or start a
service to download a file in the background.
Intent Types: Implicit Intents
• Implicit intents do not name a specific
component, but instead declare a general
action to perform, which allows a component
from another app to handle it.
• For example, if you want to show the user a
location on a map, you can use an implicit
intent to request that another capable app
show a specified location on a map.
Intent Types: Implicit Intents
How an implicit intent is delivered through the system to start
another activity?

[1] Activity A creates an Intent with an action description and passes it to startActivity().
[2] The Android System searches all apps for an intent filter that matches the intent. When a match is found,
[3] the system starts the matching activity (Activity B) by invoking its onCreate() method and passing it the
Intent.
Intent Structure
• The primary pieces of information in an intent
are:
– action -- The general action to be performed.
– data -- The data to operate on, such as a person
record in the contacts database, expressed as a
Uri.
Intent Action Examples
ACTION_VIEW
• Use this action in an intent with startActivity() when
you have some information that an activity can
show to the user, such as a photo to view in a
gallery app, or an address to view in a map app.
ACTION_SEND
• Also known as the share intent, you should use this
in an intent with startActivity() when you have
some data that the user can share through another
app, such as an email app or social sharing app.
Implicit Intent Example
//Google maps through intent.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);
 
 
 
//SMS through intent.
String number = "12346556"; // The number on which you want to send SMS
startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null)));

//Opening browser through intent


String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

You might also like