From 41801b43d86bbca4e7b98993d8d573cee75b0ae1 Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Thu, 2 Mar 2017 13:23:12 -0800 Subject: [PATCH] Save TaskRecord before calling performClearTaskLocked. If the activity exists in a task that is in persistent storage, the task reference will be cleared when its brought to the foreground in this method. Alternatively, if the activity is finished immediately as a result of clearing task, the task reference will be lost. Therefore, we must persist the task reference before calling it. Change-Id: Id38cf6654f5d4f5b727441048dc6b9a7568b574e Fixes: 35868563 Test: manual (code and bugreport inspection) --- .../core/java/com/android/server/am/ActivityStarter.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java index 857241afa0a88..94656c4eb2e38 100644 --- a/services/core/java/com/android/server/am/ActivityStarter.java +++ b/services/core/java/com/android/server/am/ActivityStarter.java @@ -1556,9 +1556,13 @@ class ActivityStarter { == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK)) { // The caller has requested to completely replace any existing task with its new // activity. Well that should not be too hard... - intentActivity.task.performClearTaskLocked(); - intentActivity.task.setIntent(mStartActivity); + // Note: we must persist the {@link TaskRecord} first as intentActivity could be + // removed from calling performClearTaskLocked (For example, if it is being brought out + // of history or if it is finished immediately), thus disassociating the task. mReuseTask = intentActivity.task; + mReuseTask.performClearTaskLocked(); + mReuseTask.setIntent(mStartActivity); + // When we clear the task - focus will be adjusted, which will bring another task // to top before we launch the activity we need. This will temporary swap their // mTaskToReturnTo values and we don't want to overwrite them accidentally.