Skip to content

Commit 4f832bc

Browse files
scottamainAndroid Git Automerger
authored andcommitted
am 3b1c5d5: add tip about including android:id for layout state
* commit '3b1c5d55517260516bfa5591ca08bb39d336d511': add tip about including android:id for layout state
2 parents 9b51638 + 3b1c5d5 commit 4f832bc

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

docs/html/training/basics/activity-lifecycle/recreating.jd

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,25 @@ load alternative resources (such as the layout).</p>
5454
<p>By default, the system uses the {@link android.os.Bundle} instance state to save information
5555
about each {@link android.view.View} object in your activity layout (such as the text value entered
5656
into an {@link android.widget.EditText} object). So, if your activity instance is destroyed and
57-
recreated, the state of the layout is automatically restored to its previous state. However, your
57+
recreated, the state of the layout is restored to its previous state with no
58+
code required by you. However, your
5859
activity might have more state information that you'd like to restore, such as member variables that
5960
track the user's progress in the activity.</p>
6061

61-
<p>In order for you to add additional data to the saved instance state for your activity, there's an
62-
additional callback method in the activity lifecycle that's not shown in the illustration from
63-
previous lessons. The method is {@link android.app.Activity#onSaveInstanceState
64-
onSaveInstanceState()} and the system calls it when the user is leaving your activity. When the
65-
system calls this method, it passes the {@link android.os.Bundle} object that will be saved in the
66-
event that your activity is destroyed unexpectedly so you can add additional information to it. Then
67-
if the system must recreate the activity instance after it was destroyed, it passes the same {@link
68-
android.os.Bundle} object to your activity's {@link android.app.Activity#onRestoreInstanceState
69-
onRestoreInstanceState()} method and also to your {@link android.app.Activity#onCreate onCreate()}
70-
method.</p>
62+
<p class="note"><strong>Note:</strong> In order for the Android system to restore the state of
63+
the views in your activity, <strong>each view must have a unique ID</strong>, supplied by the
64+
<a href="{@docRoot}reference/android/view/View.html#attr_android:id">{@code
65+
android:id}</a> attribute.</p>
66+
67+
<p>To save additional data about the activity state, you must override
68+
the {@link android.app.Activity#onSaveInstanceState onSaveInstanceState()} callback method.
69+
The system calls this method when the user is leaving your activity
70+
and passes it the {@link android.os.Bundle} object that will be saved in the
71+
event that your activity is destroyed unexpectedly. If
72+
the system must recreate the activity instance later, it passes the same {@link
73+
android.os.Bundle} object to both the {@link android.app.Activity#onRestoreInstanceState
74+
onRestoreInstanceState()} and {@link android.app.Activity#onCreate onCreate()}
75+
methods.</p>
7176

7277
<img src="{@docRoot}images/training/basics/basic-lifecycle-savestate.png" />
7378
<p class="img-caption"><strong>Figure 2.</strong> As the system begins to stop your activity, it

0 commit comments

Comments
 (0)