Activity Transition: fix quick back after enter.
Bug 19105460
When an Activity Transition was receiving an exit call
immediately after the enter, the transition for the enter
was still in progress. TransitionManager does not allow
multiple transitions to work at once, so the enter transition
would run, but the exit did not. This CL detects when the
enter transition is still pending and tells the
ActivityTransitionState to delay one frame so that the
enter can finish its required work prior to starting the
exit transition.
Change-Id: I1b40f1e41d61a67da3fd672419ea321e7d0496da
diff --git a/core/java/android/app/ActivityTransitionState.java b/core/java/android/app/ActivityTransitionState.java
index 555d20b..a2bfa4e 100644
--- a/core/java/android/app/ActivityTransitionState.java
+++ b/core/java/android/app/ActivityTransitionState.java
@@ -22,6 +22,7 @@
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
import android.view.Window;
import java.lang.ref.WeakReference;
@@ -252,7 +253,7 @@
}
}
- public boolean startExitBackTransition(Activity activity) {
+ public boolean startExitBackTransition(final Activity activity) {
if (mEnteringNames == null) {
return false;
} else {
@@ -260,10 +261,11 @@
mHasExited = true;
Transition enterViewsTransition = null;
ViewGroup decor = null;
+ boolean delayExitBack = false;
if (mEnterTransitionCoordinator != null) {
enterViewsTransition = mEnterTransitionCoordinator.getEnterViewsTransition();
decor = mEnterTransitionCoordinator.getDecor();
- mEnterTransitionCoordinator.cancelEnter();
+ delayExitBack = mEnterTransitionCoordinator.cancelEnter();
mEnterTransitionCoordinator = null;
if (enterViewsTransition != null && decor != null) {
enterViewsTransition.pause(decor);
@@ -275,7 +277,23 @@
if (enterViewsTransition != null && decor != null) {
enterViewsTransition.resume(decor);
}
- mReturnExitCoordinator.startExit(activity.mResultCode, activity.mResultData);
+ if (delayExitBack && decor != null) {
+ final ViewGroup finalDecor = decor;
+ decor.getViewTreeObserver().addOnPreDrawListener(
+ new ViewTreeObserver.OnPreDrawListener() {
+ @Override
+ public boolean onPreDraw() {
+ finalDecor.getViewTreeObserver().removeOnPreDrawListener(this);
+ if (mReturnExitCoordinator != null) {
+ mReturnExitCoordinator.startExit(activity.mResultCode,
+ activity.mResultData);
+ }
+ return true;
+ }
+ });
+ } else {
+ mReturnExitCoordinator.startExit(activity.mResultCode, activity.mResultData);
+ }
}
return true;
}