Merge "Recycling already running activities" into ub-launcher3-master
diff --git a/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java b/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java
index 0c5b9ad..664958a 100644
--- a/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java
+++ b/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java
@@ -48,7 +48,9 @@
         // b/143488140
         mLauncher.pressHome();
         // Start an activity where the gestures start.
-        startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
+        if (mLauncher.getRecentTasks().isEmpty()) {
+            startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
+        }
     }
 
     private void runTest(String... eventSequence) {
diff --git a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
index bf093fd..ed25cc7 100644
--- a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
+++ b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
@@ -69,14 +69,16 @@
     }
 
     private void startTestApps() throws Exception {
-        startAppFast(getAppPackageName());
-        startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
-        startTestActivity(2);
+        if (mLauncher.getRecentTasks().size() < 3) {
+            startAppFast(getAppPackageName());
+            startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
+            startTestActivity(2);
 
-        executeOnLauncher(launcher -> assertTrue(
-                "Launcher activity is the top activity; expecting another activity to be the top "
-                        + "one",
-                isInBackground(launcher)));
+            executeOnLauncher(launcher -> assertTrue(
+                    "Launcher activity is the top activity; expecting another activity to be the "
+                            + "top one",
+                    isInBackground(launcher)));
+        }
     }
 
     @Test