Lecture06 Intents
Lecture06 Intents
[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)));