androidandroid-activityandroid-animationlistenertransition

Detect activity transition to complete before starting a new animation in the new activity on Android Studio


I have 2 activities in Android Studio. When I clicked on a button in Activity A, it will transition to Activity B. I have an animation using xml and it would cause an transition animation from A to B.

However after completed transition from A to B, I wanted a new animation to start. For example, I wanted to a Text to appear using alpha animation. When I create the alpha animation, it seems like it is overlapping with the transition animation.

Is there a method to create a listener to wait for the transition animation to complete in Activity B, before the alpha animation starts? I don't want to create a delay in Activity B, as I am looking for a listener method to accurately detect the end of the transition animation.


Solution

  • Check getEnterTransition method of Window class.

    class B extends Activity{
    
        @Override
        public void onCreate(Bundle state){
           super.onCreate(state);
    
           getWindow().getEnterTransition().addListener(new TransitionListenerAdapter() {
                @Override
                public void onTransitionEnd(Transition transition) {
                    //start another animation here
                }
            })
        }
    }