Search code examples
androidandroid-animationandroid-5.0-lollipopandroid-transitions

Shared Elements EXIT Transition never used ?


Intro

I am currently working with Activity Transitions and Shared Elements.


What I know

I understand how the content Transitions work. They play in this order when going A -> B :

  1. Exit Transition on A Activity
  2. Background of B Activity fading in
  3. Enter Transition on the B Activity

And then when going B -> A :

  1. Return Transition on B Activity
  2. Background of A Activity fading in
  3. Reenter Transition on A Activity

Also to be able to see all these Transitions one after the other, the two following attributes must be set to false :

  • setAllowEnterTransitionOverlap
  • setAllowReturnTransitionOverlap

My problem

Now come into play the Shared Element Transitions!

I notice that no matter the configuration, the Transition SharedElementExitTransition is never played.

No matter what it it always the SharedElementEnterTransition that is used.

So far I tried :

  • Deactivate TransitionOverlap and use a long Exit (content) Transition
  • Set two different Transition for SharedElement Enter & Exit Transitions
  • Completely deactivate SharedElementEnterTransition

In all these situations ShareElementExitTransition is never used!


My question

  • Is this the normal behavior ?
  • If yes, what is the point of this Transition ?

Thank you in advance for your answers.


Solution

  • The SharedElementExitTransition is for doing something to the shared element prior to moving it to the called Activity. For example, you may want to lift it and move it to the center of the screen before the called Activity takes over.

    The important part is that the shared element exit transition is executed after you call startActivity. So you must make the change to the shared element at that point. Essentially, you do this:

    startActivity(intent, activityOptionsBundleWithTransitions);
    manipulateSharedElement();
    

    Then the shared element exit transition will execute and not transfer the shared element until after it completes. Shared element exit transitions are rarely used.