0

I have two Activities A and B which have a SharedElement. If Activity A starts Activity B and listens to the the transition, both the listener for exit and reenter are called.

Here the code for the calling Activity A:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        getWindow().getSharedElementReenterTransition().addListener(new Transition.TransitionListener() {
            @Override
            public void onTransitionStart(Transition transition) {
                Log.i("Log", "A REENTER");
            }

            ...
        });

        getWindow().getSharedElementExitTransition().addListener(new Transition.TransitionListener() {
            @Override
            public void onTransitionStart(Transition transition) {
                Log.i("Log", "A EXIT");
            }

           ...
        });

        getWindow().getSharedElementEnterTransition().addListener(new Transition.TransitionListener() {
            @Override
            public void onTransitionStart(Transition transition) {
                Log.i("TestApp", "A ENTER");


            }

            ...
        });
        getWindow().getSharedElementReturnTransition().addListener(new  Transition.TransitionListener() {
            @Override
            public void onTransitionStart(Transition transition) {
                Log.i("TestApp", "A RETURN");
            }

            ...
        });


    }

    public void onClick(View v){
        Intent intent = new Intent(this, Act2.class);
        Pair<View, String> pair1 = Pair.create(findViewById(R.id.textView), findViewById(R.id.textView).getTransitionName());
        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, pair1);
        startActivity(intent, options.toBundle());
    }
}

If I now execute onClick() (to start Activity B) and then hit the back button to return to Activity A, the Log will be as follows:

A REENTER
A EXIT
B ENTER
B RETURN
B ENTER
B RETURN
A REENTER
A EXIT

I would expect it to be

A EXIT
B ENTER
B RETURN
A REENTER
AljoSt
  • 439
  • 4
  • 19

2 Answers2

1

By default, the same transition is used for both the exit and reenter transitions as well as the enter and return transitions. If you explicitly set them, they will be different.

I believe that you are adding listeners to the same transition, so they are all being called.

George Mount
  • 20,708
  • 2
  • 73
  • 61
  • Thanks a lot. Even though I read a couple of times that they are the same if not explicitly set, I didn't imagine that both listeners would be called. Seems weird – AljoSt Sep 30 '16 at 16:54
0

I ran into the similar problem and found a similar question

There is a bug in Lollipop that causes the shared element return transition to be interrupted if it takes longer than the reenter transition duration. If you adjust your reenter transition duration (on the calling Activity), that should fix the interruption problem.

You better use the enter and return shared element transitions.

Community
  • 1
  • 1
Raymond Chenon
  • 11,482
  • 15
  • 77
  • 110
  • My transitions consist of nothing more than the code above. So they should not take long. Also how does that help me if I need to have the possibility to do different things during onExit and onReenter? [I adjusted the original post, to provide more information. ] – AljoSt Jul 27 '16 at 04:43