skip to Main Content

Let’s say I have 3 activities: A, B, and C. The order goes like A to B to C. I want to add enter and exit animations to B. When I open B from A, B should have slide up animation. When I go from B to C, B should have slide down animation. Here is my code:

In the Activity A:

startActivity(new Intent(this, B.class));
overridePendingTransition(R.anim.slide_up,  R.anim.no_animation); // working, I can see B is opening with slide up animation

In the Activity B:

startActivity(new Intent(this, C.class));
overridePendingTransition(R.anim.no_animation,  R.anim.slide_down); // not working, slide down is not applied to B

I also tried settings window enter and exit animations in the theme XML file of B. But it is not working.

Any solution?

2

Answers


  1. You should pass 0 for no_animation

    As Document said,

    Params:

    • enterAnim – A resource ID of the animation resource to use for the incoming activity. Use 0 for no animation.
    • exitAnim – A resource ID of the animation resource to use for the outgoing activity. Use 0 for no animation.

    Try with pass 0 in parameter instead of R.anim.no_animation. It might show Slide-Down animatation for Activity B.

    startActivity(new Intent(this, C.class));
    overridePendingTransition(0, R.anim.slide_down);
    
    Login or Signup to reply.
  2. We can use activities navigation using navigation component. In navigation component, we can define enter and exit animation. Please check the possibilites.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search