1. Understanding Intents
1.1 Notes
1.2 Available Intents in Android
1.3 Using Extra Information
1.4 Using Extra Information (cont.)
1.5 Using Components to Directly Invoke an Activity
1.6 Using Components to Directly Invoke an Activity (cont.)
2. Activity
2.1 Activity Lifecycle
2.2 Launching Activities and Sub-Activities(cont.)
3. Exercise 6
5. Android Programming
Understanding Intents
Just as a Web browser knows how to process a verb
+ URL pair, Android knows how to find activities or
other application logic that will handle a given intent.
You can use intents to represent actions.
At the simplest level, an intent is an action that you
can tell Android to invoke.
5
7. Android Programming
Understanding Intents
Notes:
android:exported: Whether or not the activity can be launched
by components of other applications — "true" if it can be, and
"false" if not.
The general convention for an action name is <your-package-
name>.intent.action.YOUR_ACTION_NAME.
7
8. Android Programming
Understanding Intents
Available Intents in Android
http://developer.android.com/guide/appendix/g-app-intents.html
A browser application to open a browser window
An application to call a telephone number
An application to present a phone dialer so the user can enter
the numbers and make the call through the UI
A mapping application to show the map of the world at a given
latitude/longitude coordinate
A detailed mapping application that can show Google stree
views
8
10. Android Programming
Understanding Intents
Using Extra Information
An extra can provide more information to the component that
receives the intent.
This extra information is repre-sented by an Android class called
android.os.Bundle.
The following two methods on an Intentclass provide access to
the extra Bundle:
10
13. Android Programming
Understanding Intents
Using Components to Directly Invoke an Activity
Android also provides a more direct way to start an activity: you
can specify the activity’s ComponentName, which is an
abstraction around an object’s package name and class name.
13
14. Android Programming
Understanding Intents
Using Components to Directly Invoke an Activity
(cont.)
ComponentName wraps a package name and a class name
together. For example, the follow-ing code invokes the
SubActivity:
14
15. Android Programming
Understanding Intents
Using Components to Directly Invoke an Activity
(cont.)
You can also use the class name directly without constructing a
ComponentName.
You should register the activity in the AndroidManifest.xml file
like this:
• <activity android:name=".SubActivity">
15
16. Android Programming
Understanding Intents
Using Components to Directly Invoke an Activity
(cont.)
No intent-filters are necessary for invoking an activity directly
through its class name or component name.
16
18. Android Programming
Activity
Activity Lifecycle
Most management of the life cycle is done automatically by the
system via the activity stack.
The activity class has the following method callbacks to help you
manage the app:
• onCreate()
• onStart()
• onResume()
• onPause()
• onStop()
• onRestart()
• onDestroy()
18
25. Android Programming
Activity
Launching Activities and Sub-Activities(cont.)
The Request Code: The request code that was used to launch
the returning sub-Activity
A Result Code: The result code set by the sub-Activity to
indicate its result. It can be any inte-ger value, but typically will
be either Activity.RESULT_OK or
Activity.RESULT_CANCELLED.
25
26. Android Programming
Activity
Launching Activities and Sub-Activities(cont.)
If the sub-Activity closes abnormally or doesn’t specify a result
code before it closes, the result code is
Activity.RESULT_CANCELED.
Data: An Intent used to bundle any returned data.
26