diff --git a/docs/html/guide/topics/fundamentals/activities.jd b/docs/html/guide/topics/fundamentals/activities.jd index cb453da688270..3b311997e4b5d 100644 --- a/docs/html/guide/topics/fundamentals/activities.jd +++ b/docs/html/guide/topics/fundamentals/activities.jd @@ -19,9 +19,10 @@ page.title=Activities
-Figure 2. The two ways in which an activity returns to user -focus with its state intact: either the activity is stopped, then resumed and the activity state -remains intact (left), or the activity is destroyed, then recreated and the activity must restore -the previous activity state (right).
-However, when the system destroys an activity in order to recover memory, the {@link android.app.Activity} object is destroyed, so the system cannot simply resume it with its state intact. Instead, the system must recreate the {@link android.app.Activity} object if the user @@ -630,26 +623,35 @@ navigates back to it. Yet, the user is unaware that the system destroyed the activity and recreated it and, thus, probably expects the activity to be exactly as it was. In this situation, you can ensure that important information about the activity state is preserved by implementing an additional -callback method that allows you to save information about the state of your activity and then -restore it when the the system recreates the activity.
+callback method that allows you to save information about the state of your activity: {@link +android.app.Activity#onSaveInstanceState onSaveInstanceState()}. -The callback method in which you can save information about the current state of your activity is -{@link android.app.Activity#onSaveInstanceState onSaveInstanceState()}. The system calls this method -before making the activity vulnerable to being destroyed and passes it -a {@link android.os.Bundle} object. The {@link android.os.Bundle} is where you can store +
The system calls {@link android.app.Activity#onSaveInstanceState onSaveInstanceState()} +before making the activity vulnerable to destruction. The system passes this method +a {@link android.os.Bundle} in which you can save state information about the activity as name-value pairs, using methods such as {@link -android.os.Bundle#putString putString()}. Then, if the system kills your activity's -process and the user navigates back to your activity, the system passes the {@link -android.os.Bundle} to {@link android.app.Activity#onCreate onCreate()} so you can restore the -activity state you saved during {@link android.app.Activity#onSaveInstanceState -onSaveInstanceState()}. If there is no state information to restore, then the {@link -android.os.Bundle} passed to {@link android.app.Activity#onCreate onCreate()} is null.
+android.os.Bundle#putString putString()} and {@link +android.os.Bundle#putInt putInt()}. Then, if the system kills your application +process and the user navigates back to your activity, the system recreates the activity and passes +the {@link android.os.Bundle} to both {@link android.app.Activity#onCreate onCreate()} and {@link +android.app.Activity#onRestoreInstanceState onRestoreInstanceState()}. Using either of these +methods, you can extract your saved state from the {@link android.os.Bundle} and restore the +activity state. If there is no state information to restore, then the {@link +android.os.Bundle} passed to you is null (which is the case when the activity is created for +the first time). + +
+Figure 2. The two ways in which an activity returns to user +focus with its state intact: either the activity is destroyed, then recreated and the activity must restore +the previously saved state, or the activity is stopped, then resumed and the activity state +remains intact.
Note: There's no guarantee that {@link android.app.Activity#onSaveInstanceState onSaveInstanceState()} will be called before your activity is destroyed, because there are cases in which it won't be necessary to save the state (such as when the user leaves your activity using the BACK key, because the user is explicitly -closing the activity). If the method is called, it is always called before {@link +closing the activity). If the system calls {@link android.app.Activity#onSaveInstanceState +onSaveInstanceState()}, it does so before {@link android.app.Activity#onStop onStop()} and possibly before {@link android.app.Activity#onPause onPause()}.
@@ -657,17 +659,17 @@ onPause()}. android.app.Activity#onSaveInstanceState onSaveInstanceState()}, some of the activity state is restored by the {@link android.app.Activity} class's default implementation of {@link android.app.Activity#onSaveInstanceState onSaveInstanceState()}. Specifically, the default -implementation calls {@link -android.view.View#onSaveInstanceState onSaveInstanceState()} for every {@link android.view.View} -in the layout, which allows each view to provide information about itself +implementation calls the corresponding {@link +android.view.View#onSaveInstanceState onSaveInstanceState()} method for every {@link +android.view.View} in the layout, which allows each view to provide information about itself that should be saved. Almost every widget in the Android framework implements this method as appropriate, such that any visible changes to the UI are automatically saved and restored when your activity is recreated. For example, the {@link android.widget.EditText} widget saves any text entered by the user and the {@link android.widget.CheckBox} widget saves whether it's checked or not. The only work required by you is to provide a unique ID (with the {@code android:id} -attribute) for each widget you want to save its state. If a widget does not have an ID, then it -cannot save its state. +attribute) for each widget you want to save its state. If a widget does not have an ID, then the +system cannot save its state.Note: Because {@link android.app.Activity#onSaveInstanceState onSaveInstanceState()} is not guaranteed @@ -701,7 +705,7 @@ to a database) when the user leaves the activity.
A good way to test your application's ability to restore its state is to simply rotate the device so that the screen orientation changes. When the screen orientation changes, the system destroys and recreates the activity in order to apply alternative resources that might be available -for the new orientation. For this reason alone, it's very important that your activity +for the new screen configuration. For this reason alone, it's very important that your activity completely restores its state when it is recreated, because users regularly rotate the screen while using applications.
@@ -709,22 +713,25 @@ using applications.Some device configurations can change during runtime (such as screen orientation, keyboard -availability, and language). When such a change occurs, Android restarts the running Activity -({@link android.app.Activity#onDestroy} is called, followed immediately by {@link -android.app.Activity#onCreate onCreate()}). The restart behavior is +availability, and language). When such a change occurs, Android recreates the running activity +(the system calls {@link android.app.Activity#onDestroy}, then immediately calls {@link +android.app.Activity#onCreate onCreate()}). This behavior is designed to help your application adapt to new configurations by automatically reloading your -application with alternative resources that you've provided. If you design your activity to -properly handle this event, it will be more resilient to unexpected events in the activity -lifecycle.
+application with alternative resources that you've provided (such as different layouts for +different screen orientations and sizes). -The best way to handle a configuration change, such as a change in the screen orientation, is - to simply preserve the state of your application using {@link +
If you properly design your activity to handle a restart due to a screen orientation change and +restore the activity state as described above, your application will be more resilient to other +unexpected events in the activity lifecycle.
+ +The best way to handle such a restart is + to save and restore the state of your activity using {@link android.app.Activity#onSaveInstanceState onSaveInstanceState()} and {@link android.app.Activity#onRestoreInstanceState onRestoreInstanceState()} (or {@link android.app.Activity#onCreate onCreate()}), as discussed in the previous section.
-For a detailed discussion about configuration changes that happen at runtime and how you should
-handle them, read Handling
+ For more information about configuration changes that happen at runtime and how you can handle
+them, read the guide to Handling
Runtime Changes. Figure 2. The lifecycle of a fragment (while its
activity is running). Figure 3. The activity lifecycle's affect on the fragment
lifecycle. In order to add fragment B to the back stack so that this is possible, you must call {@link
android.app.FragmentTransaction#addToBackStack addToBackStack()} before you {@link
android.app.FragmentTransaction#commit()} the transaction that replaces fragment B with fragment
@@ -93,17 +93,17 @@ is created and the "main" activity for that application opens as the root activi
When the current activity starts another, the new activity is pushed on the top of the stack and
takes focus. The previous activity remains in the stack, but is stopped. When an activity
stops, the system retains the current state of its user interface. When the user presses the BACK
-key, the current activity is popped from the top of the stack (the activity is destroyed) and the
+button, the current activity is popped from the top of the stack (the activity is destroyed) and the
previous activity resumes (the previous state of its UI is restored). Activities in the stack are
never rearranged, only pushed and popped from the stack—pushed onto the stack when started by
-the current activity and popped off when the user leaves it using the BACK key. As such, the back
+the current activity and popped off when the user leaves it using the BACK button. As such, the back
stack operates as a "last in, first out" object structure. Figure 1 visualizes
this behavior with a timeline showing the progress between activities along with the current back
stack at each point in time. Figure 1. A representation of how each new activity in a
-task adds an item to the back stack. When the user presses the BACK key, the current activity is
+task adds an item to the back stack. When the user presses the BACK button, the current activity is
destroyed and the previous activity resumes. Figure 2. Two tasks: Task A is in the background, waiting
-to be resumed, while Task B receives user interaction in the foreground. Figure 3. A single activity is instantiated multiple times. A task is a cohesive unit that can move to the "background" when users begin a new task or go
-to the Home screen, via the HOME key. While in the background, all the activities in the task are
+to the Home screen, via the HOME button. While in the background, all the activities in the task are
stopped, but the back stack for the task remains intact—the task has simply lost focus while
another task takes place, as shown in figure 2. A task can then return to the "foreground" so users
can pick up where they left off. Suppose, for example, that the current task (Task A) has three
-activities in its stack—two under the current activity. The user presses the HOME key, then
+activities in its stack—two under the current activity. The user presses the HOME button, then
starts a new application from the application launcher. When the Home screen appears, Task A goes
into the background. When the new application starts, the system starts a task for that application
(Task B) with its own stack of activities. After interacting with
@@ -135,7 +135,7 @@ started Task A. Now, Task A comes to the
foreground—all three activities in its stack are intact and the activity at the top of the
stack resumes. At
this point, the user can also switch back to Task B by going Home and selecting the application icon
-that started that task (or by touching and holding the HOME key to reveal recent tasks and selecting
+that started that task (or by touching and holding the HOME button to reveal recent tasks and selecting
one). This is an example of multitasking on Android. Note: Multiple tasks can be held in the background at once.
@@ -148,7 +148,7 @@ users to start a particular activity from more than one activity, a new instance
that activity is created and popped onto the stack (rather than bringing any previous instance of
the activity to the top). As such, one activity in your application might be instantiated multiple
times (even from different tasks), as shown in figure 3. As such, if the user navigates backward
-using the BACK key, each instance of the activity is revealed in the order they were opened (each
+using the BACK button, each instance of the activity is revealed in the order they were opened (each
with their own UI state). However, you can modify this behavior if you do not want an activity to be
instantiated more than once. How to do so is discussed in the later section about Managing Tasks. Caution: Most applications should not interrupt the default
behavior for activities and tasks. If you determine that it's necessary for your activity to modify
the default behaviors, use caution and be sure to test the usability of the activity during
-launch and when navigating back to it from other activities and tasks with the BACK key. Be sure
+launch and when navigating back to it from other activities and tasks with the BACK button. Be sure
to test for navigation behaviors that might conflict with the user's expected behavior. Note: When a new instance of an activity is created,
-the user can press the BACK key to return to the previous activity. But when an existing instance of
-an activity handles a new intent, the user cannot press the BACK key to return to the state of
+the user can press the BACK button to return to the previous activity. But when an existing instance of
+an activity handles a new intent, the user cannot press the BACK button to return to the state of
the activity before the new intent arrived in {@link android.app.Activity#onNewIntent
onNewIntent()}. Note: Although the activity starts in a new task, the
-BACK key still returns the user to the previous activity. Regardless of whether an activity starts in a new task or in the same task as the activity that
-started it, the BACK key always takes the user to the previous activity. However, if you
-start an activity from your task (Task A) that specifies the {@code singleTask} launch mode, then
-that activity might have an instance in the background that belongs to a task with its own back
-stack (Task B). In this
-case, when Task B is brought forward to handle a new intent, the BACK key first navigates
-backward through the activities in Task B before returning to
-the top-most activity in Task A. Figure 4 visualizes this type of scenario. Figure 4. A representation of how an activity with
launch mode "singleTask" is added to the back stack. If the activity is already a part of a
-background task with its own back stack (Task B), then the entire back stack also comes
-forward, on top of the current task (Task A). For more information about using launch modes in the manifest file, see the
If this flag causes an activity to begin a new task and the user presses the HOME key to leave
+ If this flag causes an activity to begin a new task and the user presses the HOME button to leave
it, there must be some way for the user to navigate back to the task. Some entities (such as the
notification manager) always start activities in an external task, never as part of their own, so
they always put {@code FLAG_ACTIVITY_NEW_TASK} in the intents they pass to {@link
@@ -549,9 +547,9 @@ android.content.Intent#ACTION_MAIN}
and a {@link android.content.Intent#CATEGORY_LAUNCHER}
filter. Imagine, for example, what could happen if the filter is missing: An intent launches a
{@code "singleTask"} activity, initiating a new task, and the user spends some time working in
-that task. The user then presses the HOME key. The task is now sent to the background and not
-visible. Because it is not represented in the application launcher, the user has no way to return to
-the task.
+that task. The user then presses the HOME button. The task is now sent to the background and is
+not visible. Now the user has no way to return to the task, because it is not represented in the
+application launcher.
For those cases where you don't want the user to be able to return to an activity, set the
diff --git a/docs/html/guide/topics/resources/index.jd b/docs/html/guide/topics/resources/index.jd
index 84eac735e32d9..3f0f1eeb96116 100644
--- a/docs/html/guide/topics/resources/index.jd
+++ b/docs/html/guide/topics/resources/index.jd
@@ -28,18 +28,18 @@ to provide compatibility with different configurations, you must organize resour
project's {@code res/} directory, using various sub-directories that group resources by type and
configuration.
-Figure 1. Two different devices, both using default
-resources.
-Figure 2. Two different devices, one using alternative
-resources. For any type of resource, you can specify default and multiple
@@ -54,18 +54,16 @@ append an appropriate configuration qualifier to the directory name.
For example, while your default UI
-layout is saved in the {@code res/layout/} directory, you might specify a different UI layout to
+layout is saved in the {@code res/layout/} directory, you might specify a different layout to
be used when the screen is in landscape orientation, by saving it in the {@code res/layout-land/}
directory. Android automatically applies the appropriate resources by matching the
device's current configuration to your resource directory names. Figure 1 demonstrates how a collection of default resources from an application are applied
-to two different devices when there are no alternative resources available. Figure 2 shows
-the same application with a set of alternative resources that qualify for one of the device
-configurations, thus, the two devices uses different resources. Figure 1 illustrates how the system applies the same layout for
+two different devices when there are no alternative resources available. Figure 2 shows
+the same application when it adds an alternative layout resource for larger screens. The information above is just an introduction to how application resources work on Android.
-The following documents provide a complete guide to how you can organize your application resources,
+ The following documents provide a complete guide to how you can organize your application resources,
specify alternative resources, access them in your application, and more:
-Figure 1. Two different devices, one using alternative resources. Almost every application should provide alternative resources to support specific device
@@ -1021,8 +1021,8 @@ drawables from {@code drawable-en-port}. Figure 2. Flowchart of how Android finds the
best-matching resource.Creating a Fragment
-
Handling the Fragment Lifecycle
-
<activity>
@@ -447,7 +445,7 @@ flag, the system looks for a different task to house the new activity. Often, it
However, it doesn't have to be. If there's already an existing task with the same affinity as the
new activity, the activity is launched into that task. If not, it begins a new task.
+
+
diff --git a/docs/html/guide/topics/resources/providing-resources.jd b/docs/html/guide/topics/resources/providing-resources.jd
index 252c153a6b3d9..3a176e63de28b 100644
--- a/docs/html/guide/topics/resources/providing-resources.jd
+++ b/docs/html/guide/topics/resources/providing-resources.jd
@@ -207,10 +207,10 @@ resources.
Providing Alternative Resources
-
+
+