GhostFlying
GhostFlying

Reputation: 819

Why only the called activity's shared element enter transition run?

I tried to add my custom shared element transition in my app, and I make it work on some different modes in different activity. But in my test, only the called activity's enter transition is executed.

This is my code in the calling activity A:

    TransitionSet set = new TransitionSet();
    set.setOrdering(TransitionSet.ORDERING_TOGETHER);
    set.addTransition(new ChangeBounds());
    PortalHeaderBackgroundTransition back = new PortalHeaderBackgroundTransition();
    back.setMode(0);
    set.addTransition(back);
    getWindow().setSharedElementEnterTransition(set);

    set = new TransitionSet();
    set.setOrdering(TransitionSet.ORDERING_TOGETHER);
    set.addTransition(new ChangeBounds());
    back = new PortalHeaderBackgroundTransition();
    back.setMode(1);
    set.addTransition(back);
    getWindow().setSharedElementExitTransition(set);

This is my code in the called activity B:

    TransitionSet set = new TransitionSet();
    set.setOrdering(TransitionSet.ORDERING_TOGETHER);
    set.addTransition(new ChangeBounds());
    PortalHeaderBackgroundTransition back = new PortalHeaderBackgroundTransition();
    back.setMode(2);
    set.addTransition(back);
    getWindow().setSharedElementEnterTransition(set);

    set = new TransitionSet();
    set.setOrdering(TransitionSet.ORDERING_TOGETHER);
    set.addTransition(new ChangeBounds());
    back = new PortalHeaderBackgroundTransition();
    back.setMode(3);
    set.addTransition(back);
    getWindow().setSharedElementExitTransition(set);

I add breakpoint in my PortalHeaderBackgroundTransition, whenever the A call B or B back to A, only the mode 2 transition is executed.

Why does this happen? And when does the other transition to be executed?

Upvotes: 3

Views: 1640

Answers (1)

Alex Lockwood
Alex Lockwood

Reputation: 83303

When activity A starts activity B, the following events occur:

  1. A's exit shared element transition is run.
  2. B's enter shared element transition is run.

When B returns to A, the following events occur:

  1. B's return shared element transition is run (if no return transition is specified, B's enter shared element transition will be used instead).
  2. A's reenter shared element transition is run (if no reenter transition is specified, A's exit shared element transition will be used instead).

So to answer your question, A's enter shared element transition is never executed because that is the way activity transitions work. :)

Upvotes: 5

Related Questions