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
  • Starting an Activity
      -
    1. Starting an Activity for a Result
    2. +
    3. Starting an activity for a result
  • +
  • Shutting Down an Activity
  • Managing the Activity Lifecycle
    1. Implementing the lifecycle callbacks
    2. @@ -612,17 +613,9 @@ that when an activity is paused or stopped, the state of the activity is retained. This is true because the {@link android.app.Activity} object is still held in memory when it is paused or stopped—all information about its members and current state is still alive. Thus, any changes -the user made within the activity are retained in memory, so that when the activity returns to the +the user made within the activity are retained so that when the activity returns to the foreground (when it "resumes"), those changes are still there.

      -
      - -

      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.