Android Training Lesson 6: FPT Software
Android Training Lesson 6: FPT Software
ANDROID TRAINING
LESSON 6
Version 0.1
• Android Intents
• Using Intents to call Activities
• Defining Intent Filters
• Intents as event triggers
• Share Intent and ShareActionProvider
• Finding out if an Intent is available
• Action Field
– A string naming the action to be performed
– The Intent class defines a number of pre-defined action
constants, including
• ACTION_CALL, ACTION_EDIT, ACTION_MAIN, ACTION_SYNC,
ACTION_BATTERY_LOW, etc.
– You can also define your own action strings for activating
the components in your application
– The action largely determines how the rest of the intent is
structured - particularly the data and extras fields - much
as a method name determines a set of arguments and a
return value.
• Data Field
– The URI of the data to be acted on and the MIME type of
that data.
– Different actions are paired with different kinds of data
specifications.
• If the action field is ACTION_EDIT, the data field would contain the
URI of the document to be displayed for editing.
• If the action is ACTION_CALL, the data field would be a tel: URI
with the number to call.
• If the action is ACTION_VIEW and the data field is an http: URI, the
receiving activity would be called upon to download and display
whatever data the URI refers to.
• Category Field
– A string containing additional information about
the kind of component (activity, service, or
broadcast receiver) that should handle the intent.
– Any number of category descriptions can be
placed in an Intent object
– Android provides a set of predefined categories
(We will see them in the following slide)
– You can define your own categories
• Extras Field
– Key-value pairs for additional information that should be
delivered to the component handling the intent.
– Just as some actions are paired with particular kinds of
data URIs, some are paired with particular extras.
• ACTION_TIMEZONE_CHANGED action has a "time-zone" extra that
identifies the new time zone
• ACTION_HEADSET_PLUG action has a "state" extra indicating
whether the headset is now plugged in or unplugged , as well as a
"name" extra for the type of headset
• If you were to invent a SHOW_COLOR action, the color value
would be set in an extra key-value pair.
• Flags Field
– Flags of various sorts.
– Many instruct the Android system how to launch
an activity (for example, which task the activity
should belong to) and how to treat it after it's
launched (for example, whether it belongs in the
list of recent activities).
• Types of Intents
– Explicit intents
– Implicit intents
• Create Notification
• Click on Notification to start active with extra
data