Jin
Jin

Reputation: 6145

Understanding activity return transitions

I am currently using a custom shared element transition for when I launch Activity B from activity A. Everything works perfectly.

I want to use another custom Transition that doesn't involve any shared elements for the return transition from activity B back to activity A. However, I am having trouble with several parts:

  1. How do I tell the framework that the return transition doesn't involve any shared elements?
  2. What are the start and end values for the transition in a return transition? For the enter transition, I mostly manipulated activity B's views as they are drawn on top of activity A's. What happens in a return transition?

Appreciate any help I can get!

EDIT:

Further investigation revealed that my return transition's createAnimator isn't even being called even though I'm calling setSharedElementReturnTransition. But I know the set call is doing something because it now doesn't try to reverse the original enter animation (default behavior) and instead of just overlaps the two views.

EDIT #2:

After looking at George Mount's answer, I added

@Override
public void captureStartValues(TransitionValues transitionValues) {
    transitionValues.view.setVisibility(View.VISIBLE);
}

@Override
public void captureEndValues(TransitionValues transitionValues) {
    transitionValues.view.setVisibility(View.INVISIBLE);
}

This is now causing my return transition's createAnimator to at least run albeit the animation is still weird. Why does the visibility matter?

Upvotes: 2

Views: 2497

Answers (2)

Jin
Jin

Reputation: 6145

I actually found the culprit that was causing my return transition's createAnimator to not run. Apparently, if the transition framework thinks that the starting and ending states for the transitioning views are the same, it won't create an animator. Therefore, adding some dummy but different values into captureStartState and captureEndState finally caused my return transition to run properly.

Upvotes: 3

George Mount
George Mount

Reputation: 20926

  1. You must set the SharedElementCallback and in onMapSharedElements, clear the shared element map. That will eliminate the shared element from your transition.
  2. This depends on which transition you're talking about. Specifically the return transition's start end end values are View.VISIBLE and View.INVISIBLE. But there are several transitions happening when returning:

Return Transition: non-shared elements are removed from the scene in Activity B by changing their visibility.

Shared Element Return Transition: The shared element in Activity B starts where it is when finishAfterTransition is called and ends where Activity A says the shared element is. This can be adjusted by SharedElementCallback's onSharedElementStart and onSharedElementEnd, which are called in reverse during return.

Reenter Transition: non-shared element views from Activity A change their visibility.

Shared Element Reenter Transition: usually nothing, but the shared element can do something special after it lands in Activity A.

Upvotes: 3

Related Questions