From 0b3d573e46b8be0f0cf170802214320859c94905 Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Tue, 17 Mar 2015 11:36:24 -0700 Subject: [PATCH] Recompute focus stack if cleared while starting an activity. When starting an activity with Intent.FLAG_ACTIVITY_CLEAR_TOP flag, the activity is destoried which can also cause its task to be removed from its current stack if the activity process record is null. We now recompute the stack for the activity task when this occurs so we don't NPE later on. Bug: 19552874 Change-Id: I50f51ca6dc32d4642f78d59cae93b0774bc6cdb7 (cherry picked from commit 86920fe630911cbbc0839b341dc694c2b905ef9e) --- .../server/am/ActivityStackSupervisor.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 0630cad95c328..8d1140de8924c 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -1939,15 +1939,22 @@ public final class ActivityStackSupervisor implements DisplayListener { r, top.task); top.deliverNewIntentLocked(callingUid, r.intent, r.launchedFromPackage); } else { - // A special case: we need to - // start the activity because it is not currently - // running, and the caller has asked to clear the - // current task to have this activity at the top. + // A special case: we need to start the activity because it is not + // currently running, and the caller has asked to clear the current + // task to have this activity at the top. addingToTask = true; - // Now pretend like this activity is being started - // by the top of its task, so it is put in the - // right place. + // Now pretend like this activity is being started by the top of its + // task, so it is put in the right place. sourceRecord = intentActivity; + TaskRecord task = sourceRecord.task; + if (task != null && task.stack == null) { + // Target stack got cleared when we all activities were removed + // above. Go ahead and reset it. + targetStack = computeStackFocus(sourceRecord, false /* newTask */); + targetStack.addTask( + task, !launchTaskBehind /* toTop */, false /* moving */); + } + } } else if (r.realActivity.equals(intentActivity.task.realActivity)) { // In this case the top activity on the task is the