@@ -1129,6 +1129,11 @@ private final void completePauseLocked() {
11291129 resumeTopActivityLocked (prev );
11301130 } else {
11311131 checkReadyForSleepLocked ();
1132+ if (topRunningActivityLocked (null ) == null ) {
1133+ // If there are no more activities available to run, then
1134+ // do resume anyway to start something.
1135+ resumeTopActivityLocked (null );
1136+ }
11321137 }
11331138
11341139 if (prev != null ) {
@@ -3409,6 +3414,7 @@ final ActivityRecord activityIdleInternal(IBinder token, boolean fromTimeout,
34093414 IApplicationThread sendThumbnail = null ;
34103415 boolean booting = false ;
34113416 boolean enableScreen = false ;
3417+ boolean activityRemoved = false ;
34123418
34133419 synchronized (mService ) {
34143420 ActivityRecord r = ActivityRecord .forToken (token );
@@ -3515,7 +3521,7 @@ final ActivityRecord activityIdleInternal(IBinder token, boolean fromTimeout,
35153521 for (i =0 ; i <NF ; i ++) {
35163522 ActivityRecord r = (ActivityRecord )finishes .get (i );
35173523 synchronized (mService ) {
3518- destroyActivityLocked (r , true , false , "finish-idle" );
3524+ activityRemoved = destroyActivityLocked (r , true , false , "finish-idle" );
35193525 }
35203526 }
35213527
@@ -3537,6 +3543,10 @@ final ActivityRecord activityIdleInternal(IBinder token, boolean fromTimeout,
35373543 mService .enableScreenAfterBoot ();
35383544 }
35393545
3546+ if (activityRemoved ) {
3547+ resumeTopActivityLocked (null );
3548+ }
3549+
35403550 return res ;
35413551 }
35423552
@@ -3776,7 +3786,11 @@ private final ActivityRecord finishCurrentActivityLocked(ActivityRecord r,
37763786 || prevState == ActivityState .INITIALIZING ) {
37773787 // If this activity is already stopped, we can just finish
37783788 // it right now.
3779- return destroyActivityLocked (r , true , true , "finish-imm" ) ? null : r ;
3789+ boolean activityRemoved = destroyActivityLocked (r , true , true , "finish-imm" );
3790+ if (activityRemoved ) {
3791+ resumeTopActivityLocked (null );
3792+ }
3793+ return activityRemoved ? null : r ;
37803794 } else {
37813795 // Need to go through the full pause cycle to get this
37823796 // activity into the stopped state and then finish it.
@@ -3840,6 +3854,10 @@ final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices,
38403854 }
38413855
38423856 // Get rid of any pending idle timeouts.
3857+ removeTimeoutsForActivityLocked (r );
3858+ }
3859+
3860+ private void removeTimeoutsForActivityLocked (ActivityRecord r ) {
38433861 mHandler .removeMessages (PAUSE_TIMEOUT_MSG , r );
38443862 mHandler .removeMessages (STOP_TIMEOUT_MSG , r );
38453863 mHandler .removeMessages (IDLE_TIMEOUT_MSG , r );
@@ -3893,6 +3911,7 @@ final void scheduleDestroyActivities(ProcessRecord owner, boolean oomAdj, String
38933911
38943912 final void destroyActivitiesLocked (ProcessRecord owner , boolean oomAdj , String reason ) {
38953913 boolean lastIsOpaque = false ;
3914+ boolean activityRemoved = false ;
38963915 for (int i =mHistory .size ()-1 ; i >=0 ; i --) {
38973916 ActivityRecord r = mHistory .get (i );
38983917 if (r .finishing ) {
@@ -3916,9 +3935,14 @@ final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj, String r
39163935 if (DEBUG_SWITCH ) Slog .v (TAG , "Destroying " + r + " in state " + r .state
39173936 + " resumed=" + mResumedActivity
39183937 + " pausing=" + mPausingActivity );
3919- destroyActivityLocked (r , true , oomAdj , reason );
3938+ if (destroyActivityLocked (r , true , oomAdj , reason )) {
3939+ activityRemoved = true ;
3940+ }
39203941 }
39213942 }
3943+ if (activityRemoved ) {
3944+ resumeTopActivityLocked (null );
3945+ }
39223946 }
39233947
39243948 /**
@@ -4023,23 +4047,28 @@ final boolean destroyActivityLocked(ActivityRecord r,
40234047
40244048 final void activityDestroyed (IBinder token ) {
40254049 synchronized (mService ) {
4026- ActivityRecord r = ActivityRecord .forToken (token );
4027- if (r != null ) {
4028- mHandler .removeMessages (DESTROY_TIMEOUT_MSG , r );
4029- }
4030-
4031- int index = indexOfActivityLocked (r );
4032- if (index >= 0 ) {
4033- if (r .state == ActivityState .DESTROYING ) {
4034- final long origId = Binder .clearCallingIdentity ();
4035- removeActivityFromHistoryLocked (r );
4036- Binder .restoreCallingIdentity (origId );
4050+ final long origId = Binder .clearCallingIdentity ();
4051+ try {
4052+ ActivityRecord r = ActivityRecord .forToken (token );
4053+ if (r != null ) {
4054+ mHandler .removeMessages (DESTROY_TIMEOUT_MSG , r );
4055+ }
4056+
4057+ int index = indexOfActivityLocked (r );
4058+ if (index >= 0 ) {
4059+ if (r .state == ActivityState .DESTROYING ) {
4060+ cleanUpActivityLocked (r , true , true );
4061+ removeActivityFromHistoryLocked (r );
4062+ }
40374063 }
4064+ resumeTopActivityLocked (null );
4065+ } finally {
4066+ Binder .restoreCallingIdentity (origId );
40384067 }
40394068 }
40404069 }
40414070
4042- private static void removeHistoryRecordsForAppLocked (ArrayList list , ProcessRecord app ) {
4071+ private void removeHistoryRecordsForAppLocked (ArrayList list , ProcessRecord app ) {
40434072 int i = list .size ();
40444073 if (localLOGV ) Slog .v (
40454074 TAG , "Removing app " + app + " from list " + list
@@ -4052,6 +4081,7 @@ private static void removeHistoryRecordsForAppLocked(ArrayList list, ProcessReco
40524081 if (r .app == app ) {
40534082 if (localLOGV ) Slog .v (TAG , "Removing this entry!" );
40544083 list .remove (i );
4084+ removeTimeoutsForActivityLocked (r );
40554085 }
40564086 }
40574087 }
0 commit comments