@@ -87,6 +87,8 @@ final class ActivityStack {
8787 static final boolean DEBUG_TASKS = ActivityManagerService .DEBUG_TASKS ;
8888
8989 static final boolean DEBUG_STATES = false ;
90+ static final boolean DEBUG_ADD_REMOVE = false ;
91+ static final boolean DEBUG_SAVED_STATE = false ;
9092
9193 static final boolean VALIDATE_TOKENS = ActivityManagerService .VALIDATE_TOKENS ;
9294
@@ -653,6 +655,9 @@ final boolean realStartActivityLocked(ActivityRecord r,
653655 }
654656 completeResumeLocked (r );
655657 checkReadyForSleepLocked ();
658+ if (DEBUG_SAVED_STATE ) Slog .i (TAG , "Launch completed; removing icicle of " + r .icicle );
659+ r .icicle = null ;
660+ r .haveState = false ;
656661 } else {
657662 // This activity is not starting in the resumed state... which
658663 // should look like we asked it to pause+stop (but remain visible),
@@ -664,9 +669,6 @@ final boolean realStartActivityLocked(ActivityRecord r,
664669 r .stopped = true ;
665670 }
666671
667- r .icicle = null ;
668- r .haveState = false ;
669-
670672 // Launch the new version setup screen if needed. We do this -after-
671673 // launching the initial activity (that is, home), so that it can have
672674 // a chance to initialize itself while in the background, making the
@@ -936,6 +938,7 @@ final void activityPaused(IBinder token, boolean timeout) {
936938
937939 final void activityStoppedLocked (ActivityRecord r , Bundle icicle , Bitmap thumbnail ,
938940 CharSequence description ) {
941+ if (DEBUG_SAVED_STATE ) Slog .i (TAG , "Saving icicle of " + r + ": " + icicle );
939942 r .icicle = icicle ;
940943 r .haveState = true ;
941944 r .updateThumbnail (thumbnail , description );
@@ -1544,6 +1547,7 @@ final boolean resumeTopActivityLocked(ActivityRecord prev) {
15441547 }
15451548
15461549 // Didn't need to use the icicle, and it is now out of date.
1550+ if (DEBUG_SAVED_STATE ) Slog .i (TAG , "Resumed activity; didn't need icicle of: " + next );
15471551 next .icicle = null ;
15481552 next .haveState = false ;
15491553 next .stopped = false ;
@@ -1590,6 +1594,12 @@ private final void startActivityLocked(ActivityRecord r, boolean newTask,
15901594 // get started when the user navigates back to it.
15911595 addPos = i +1 ;
15921596 if (!startIt ) {
1597+ if (DEBUG_ADD_REMOVE ) {
1598+ RuntimeException here = new RuntimeException ("here" );
1599+ here .fillInStackTrace ();
1600+ Slog .i (TAG , "Adding activity " + r + " to stack at " + addPos ,
1601+ here );
1602+ }
15931603 mHistory .add (addPos , r );
15941604 r .putInHistory ();
15951605 mService .mWindowManager .addAppToken (addPos , r , r .task .taskId ,
@@ -1622,6 +1632,11 @@ private final void startActivityLocked(ActivityRecord r, boolean newTask,
16221632 }
16231633
16241634 // Slot the activity into the history stack and proceed
1635+ if (DEBUG_ADD_REMOVE ) {
1636+ RuntimeException here = new RuntimeException ("here" );
1637+ here .fillInStackTrace ();
1638+ Slog .i (TAG , "Adding activity " + r + " to stack at " + addPos , here );
1639+ }
16251640 mHistory .add (addPos , r );
16261641 r .putInHistory ();
16271642 r .frontOfTask = newTask ;
@@ -1818,6 +1833,12 @@ private final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop,
18181833 + " out to target's task " + target .task );
18191834 p .setTask (target .task , curThumbHolder , false );
18201835 curThumbHolder = p .thumbHolder ;
1836+ if (DEBUG_ADD_REMOVE ) {
1837+ RuntimeException here = new RuntimeException ("here" );
1838+ here .fillInStackTrace ();
1839+ Slog .i (TAG , "Removing and adding activity " + p + " to stack at "
1840+ + dstPos , here );
1841+ }
18211842 mHistory .remove (srcPos );
18221843 mHistory .add (dstPos , p );
18231844 mService .mWindowManager .moveAppToken (dstPos , p );
@@ -1945,6 +1966,12 @@ private final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop,
19451966 } else {
19461967 lastReparentPos --;
19471968 }
1969+ if (DEBUG_ADD_REMOVE ) {
1970+ RuntimeException here = new RuntimeException ("here" );
1971+ here .fillInStackTrace ();
1972+ Slog .i (TAG , "Removing and adding activity " + p + " to stack at "
1973+ + lastReparentPos , here );
1974+ }
19481975 mHistory .remove (srcPos );
19491976 p .setTask (task , null , false );
19501977 mHistory .add (lastReparentPos , p );
@@ -2143,6 +2170,12 @@ private final ActivityRecord moveActivityToFrontLocked(int where) {
21432170 ActivityRecord newTop = mHistory .remove (where );
21442171 int top = mHistory .size ();
21452172 ActivityRecord oldTop = mHistory .get (top -1 );
2173+ if (DEBUG_ADD_REMOVE ) {
2174+ RuntimeException here = new RuntimeException ("here" );
2175+ here .fillInStackTrace ();
2176+ Slog .i (TAG , "Removing and adding activity " + newTop + " to stack at "
2177+ + top , here );
2178+ }
21462179 mHistory .add (top , newTop );
21472180 oldTop .frontOfTask = false ;
21482181 newTop .frontOfTask = true ;
@@ -2183,7 +2216,7 @@ final int startActivityLocked(IApplicationThread caller,
21832216 if (resultTo != null ) {
21842217 int index = indexOfTokenLocked (resultTo );
21852218 if (DEBUG_RESULTS ) Slog .v (
2186- TAG , "Sending result to " + resultTo + " (index " + index + ")" );
2219+ TAG , "Will send result to " + resultTo + " (index " + index + ")" );
21872220 if (index >= 0 ) {
21882221 sourceRecord = mHistory .get (index );
21892222 if (requestCode >= 0 && !sourceRecord .finishing ) {
@@ -3279,34 +3312,15 @@ final ActivityRecord activityIdleInternal(IBinder token, boolean fromTimeout,
32793312 */
32803313 final boolean requestFinishActivityLocked (IBinder token , int resultCode ,
32813314 Intent resultData , String reason ) {
3282- if (DEBUG_RESULTS ) Slog .v (
3283- TAG , "Finishing activity: token=" + token
3284- + ", result=" + resultCode + ", data=" + resultData );
3285-
32863315 int index = indexOfTokenLocked (token );
3316+ if (DEBUG_RESULTS ) Slog .v (
3317+ TAG , "Finishing activity @" + index + ": token=" + token
3318+ + ", result=" + resultCode + ", data=" + resultData );
32873319 if (index < 0 ) {
32883320 return false ;
32893321 }
32903322 ActivityRecord r = mHistory .get (index );
32913323
3292- // Is this the last activity left?
3293- boolean lastActivity = true ;
3294- for (int i =mHistory .size ()-1 ; i >=0 ; i --) {
3295- ActivityRecord p = mHistory .get (i );
3296- if (!p .finishing && p != r ) {
3297- lastActivity = false ;
3298- break ;
3299- }
3300- }
3301-
3302- // If this is the last activity, but it is the home activity, then
3303- // just don't finish it.
3304- if (lastActivity ) {
3305- if (r .intent .hasCategory (Intent .CATEGORY_HOME )) {
3306- return false ;
3307- }
3308- }
3309-
33103324 finishActivityLocked (r , index , resultCode , resultData , reason );
33113325 return true ;
33123326 }
@@ -3538,6 +3552,11 @@ final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices,
35383552 private final void removeActivityFromHistoryLocked (ActivityRecord r ) {
35393553 if (r .state != ActivityState .DESTROYED ) {
35403554 r .makeFinishing ();
3555+ if (DEBUG_ADD_REMOVE ) {
3556+ RuntimeException here = new RuntimeException ("here" );
3557+ here .fillInStackTrace ();
3558+ Slog .i (TAG , "Removing activity " + r + " from stack" );
3559+ }
35413560 mHistory .remove (r );
35423561 r .takeFromHistory ();
35433562 if (DEBUG_STATES ) Slog .v (TAG , "Moving to DESTROYED: " + r
@@ -3769,6 +3788,11 @@ final void moveTaskToFrontLocked(TaskRecord tr, ActivityRecord reason) {
37693788 TAG , "At " + pos + " ckp " + r .task + ": " + r );
37703789 if (r .task .taskId == task ) {
37713790 if (localLOGV ) Slog .v (TAG , "Removing and adding at " + top );
3791+ if (DEBUG_ADD_REMOVE ) {
3792+ RuntimeException here = new RuntimeException ("here" );
3793+ here .fillInStackTrace ();
3794+ Slog .i (TAG , "Removing and adding activity " + r + " to stack at " + top , here );
3795+ }
37723796 mHistory .remove (pos );
37733797 mHistory .add (top , r );
37743798 moved .add (0 , r );
@@ -3858,6 +3882,12 @@ final boolean moveTaskToBackLocked(int task, ActivityRecord reason) {
38583882 TAG , "At " + pos + " ckp " + r .task + ": " + r );
38593883 if (r .task .taskId == task ) {
38603884 if (localLOGV ) Slog .v (TAG , "Removing and adding at " + (N -1 ));
3885+ if (DEBUG_ADD_REMOVE ) {
3886+ RuntimeException here = new RuntimeException ("here" );
3887+ here .fillInStackTrace ();
3888+ Slog .i (TAG , "Removing and adding activity " + r + " to stack at "
3889+ + bottom , here );
3890+ }
38613891 mHistory .remove (pos );
38623892 mHistory .add (bottom , r );
38633893 moved .add (r );
0 commit comments