OSDN Git Service

Recompute focus stack if cleared while starting an activity.
authorWale Ogunwale <ogunwale@google.com>
Tue, 17 Mar 2015 18:36:24 +0000 (11:36 -0700)
committerWale Ogunwale <ogunwale@google.com>
Tue, 17 Mar 2015 20:20:24 +0000 (13:20 -0700)
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

services/core/java/com/android/server/am/ActivityStackSupervisor.java

index 471737e..9472707 100644 (file)
@@ -1982,15 +1982,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