resolved conflicts for merge of aaadf922 to master

Change-Id: I8b89a326453fc8827a84eb9516271d2bf3b71e2c
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index 986321d..65d6e2f 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -114,6 +114,10 @@
     /** If original intent did not allow relinquishing task identity, save that information */
     boolean mNeverRelinquishIdentity = true;
 
+    // Used in the unique case where we are clearing the task in order to reuse it. In that case we
+    // do not want to delete the stack when the task goes empty.
+    boolean mReuseTask = false;
+
     final ActivityManagerService mService;
 
     TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
@@ -339,7 +343,7 @@
             mService.notifyTaskPersisterLocked(this, false);
         }
         if (mActivities.isEmpty()) {
-            return true;
+            return !mReuseTask;
         }
         updateEffectiveIntent();
         return false;
@@ -383,7 +387,9 @@
      * Completely remove all activities associated with an existing task.
      */
     final void performClearTaskLocked() {
+        mReuseTask = true;
         performClearTaskAtIndexLocked(0);
+        mReuseTask = false;
     }
 
     /**