FU Lecture 05 06
FU Lecture 05 06
Using Intents
Linking Activities
Today's Agenda
Invoking Activities by class name
DATA
CATEGORY
EXTRAS
FLAGS
COMPONENT NAME
Types of Intents
EXPLICIT INTENTS
These intents designate the target component by its name and they are
typically used for application-internal messages - such as an activity
starting a subordinate service or launching a sister activity.
Intent i = new Intent(this, TargetActivity.class);
IMPLICIT INTENTS
These intents do not name a target and the field for the component name
is left blank. Implicit intents are often used to activate components in
other applications.
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.example.com"));
Invoking Activities by class name
Exactly one Activity can match
Supply a URI that indirectly refers to new Activity. The new Activity
registers as target for URIs of a certain form.
Invoking Activities with a URI
Java (original Activity)
Uri uri = Uri.parse("foo://bar.example.com/baz");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent );
XML (AndroidManifest.xml)
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="foo" android:host="bar.example.com" />
</intent-filter>
Invoking Activities with a URI
Matching the URI itself
o Register for a scheme and a host
Example URI: foo://bar.example.com/baz
intent-filter entry
• <data android:scheme=“foo" android:host="bar.example.com" />
• Note that the “baz” part is arbitrary – just to make URL look better.
Matching the data type
o Register for a MIME type
Example URIs
• content:// (referring to that MIME type)
• file:// (referring to that MIME type)
• anything:// (the Intent can call setType to specify MIME type)
intent-filter entry
• <data android:mimeType="some/type" />
• <data android:mimeType="something/*" />
Predefined Action/URI Combinations
Action URI Meaning
ACTION_DIAL
ACTION_PICK
How It Works
Some examples of data include the following:
http://www.google.com
tel:+651234567
geo:37.827500,-122.481670
content://contacts
Show Map