Java Reference
In-Depth Information
linktothisotherapp.Instead,itstartsuptheotherapp'scolorchoosercomponentwhen
needed.
Android starts a process when any part of the app (e.g., the aforementioned color
chooser)isneeded,andinstantiatestheJavaobjectsforthatpart.ThisiswhyAndroid's
appsdon'thaveasingleentrypoint(noC-style main() function,forexample).Instead,
apps use components that are instantiated and run as needed.
COMMUNICATING VIA INTENTS
Activities,broadcastreceivers,andservicescommunicatewitheachothervia intents ,
whicharemessagesthatdescribeoperationstoperform(e.g.,sendanemailorchoose
a photo), or (in the case of broadcasts) provide descriptions of external events that
have occurred (a device's camera being activated, for example) and are being an-
nounced.
BecausenearlyeverythinginAndroidinvolvesintents,therearemanyopportunities
to replace existing components with your own components. For example, Android
providestheintentforsendinganemail.Yourappcansendthatintenttoactivatethe
standard mail app, or it can register an activity (discussed shortly) that responds to
the “send an email” intent, effectively replacing the standard mail app with its own
activity.
These messages are implemented as instances of the an-
droid.content.Intent class.An Intent objectdescribesamessageinterms
of some combination of the following items:
Action : A string naming the action to be performed or, in the case of
broadcast intents, the action that took place and is being reported. Actions
are described by Intent constants such as ACTION_CALL (initiate a
phone call), ACTION_EDIT (display data for the user to edit), and
ACTION_MAIN (start up as the initial activity). You can also define your
ownactionstringsforactivatingthecomponentsinyourapp.Thesestrings
should include the app package as a prefix
( "com.example.project.SELECT_COLOR" , for example).
Category : A string that provides additional information about the kind of
component that should handle the intent. For example,
CATEGORY_LAUNCHER meansthatthecallingactivityshouldappearinthe
device's app launcher as a top-level app. (The app launcher is briefly dis-
cussed later in this chapter.)
Component name :Astringthatspecifiesthefullyqualifiedname(package
plusname)ofacomponentclasstousefortheintent.Thecomponentname
Search WWH ::




Custom Search