Only return to home if the foreground task is removed.

The previous fix that returned to home when a task on top of home was
removed was too broad. If that task was not the foreground task it was
not a good idea to bring the home screen to the front.

Fixes bug 11198552.

Change-Id: I14e5fdc167011f25e0e8490c3e52c5c1dcbffbff
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
index 525b7e1..d1c313a 100644
--- a/services/java/com/android/server/am/ActivityStack.java
+++ b/services/java/com/android/server/am/ActivityStack.java
@@ -2628,10 +2628,10 @@
         if (task != null && task.removeActivity(r)) {
             if (DEBUG_STACK) Slog.i(TAG,
                     "removeActivityFromHistoryLocked: last activity removed from " + this);
-            mStackSupervisor.removeTask(task);
-            if (task.mOnTopOfHome) {
+            if (task == topTask() && task.mOnTopOfHome) {
                 mStackSupervisor.moveHomeToTop();
             }
+            mStackSupervisor.removeTask(task);
         }
         r.takeFromHistory();
         removeTimeoutsForActivityLocked(r);