Semester : SEMESTER 6
Subject : Object Oriented Programming
Year : 2018
Term : MARCH
Scheme : 2015 Full Time
Course Code : EC 312
Page:23
This field of the Intent is a ComponentName object, which you can specify using a fully qualified
class name of the target component, including the package name of the app, for example,
com.example.ExampleActivity. You can set the component name with setComponent(), setClass(),
setClassName(), or with the Intent constructor.
Action
A string that specifies the generic action to perform (such as view or pick).
In the case of a broadcast intent, this is the action that took place and is being reported. The action
largely determines how the rest of the intent is structured—particularly the information that is
contained in the data and extras.
You can specify your own actions for use by intents within your app (or for use by other apps to
invoke components in your app), but you usually specify action constants defined by the Intent class
or other framework classes. Here are some common actions for starting an activity:
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.
Data
The URI (a Uri object) that references the data to be acted on and/or the MIME type of that data. The
type of data supplied is generally dictated by the intent's action. For example, if the action is
ACTION_EDIT, the data should contain the URI of the document to edit.
When creating an intent, it's often important to specify the type of data (its MIME type) in addition to
its URI. For example, an activity that's able to display images probably won't be able to play an audio
file, even though the URI formats could be similar. Specifying the MIME type of your data helps the
Android system find the best component to receive your intent. However, the MIME type can
sometimes be inferred from the URI—particularly when the data is a content: URI. A content: URI
indicates the data is located on the device and controlled by a ContentProvider, which makes the data
MIME type visible to the system.
To set only the data URI, call setData(). To set only the MIME type, call setType(). If necessary, you
can set both explicitly with setDataAndType().
Caution: If you want to set both the URI and MIME type, don't call setData() and setType() because
they each nullify the value of the other. Always use setDataAndType() to set both URI and MIME
type.