Home » Android » How to provide animation when calling another activity in Android?

How to provide animation when calling another activity in Android?

Posted by: admin March 11, 2020 Leave a comment


I have two Activities A and B. I want to have the shrink Animation when
Activity A calls B and maximize animation when Activity B calls A. I don’t need the animation xml files for this.

When we call another Activity in Android it gives its default animation and then it calls shrink animation.

What I want is that the default animation should not occur and the animation that I want should occur.

Can we actually give the animation when calling another Activity?

How to&Answers:

Since API 16 you can supply an activity options bundle when calling Context.startActivity(Intent, Bundle) or related methods. It is created via the ActivityOptions builder:

Intent myIntent = new Intent(context, MyActivity.class);
ActivityOptions options = 
   ActivityOptions.makeCustomAnimation(context, R.anim.fade_in, R.anim.fade_out);
context.startActivity(myIntent, options.toBundle());

Don’t forget to check out the other methods of the ActivityOptions builder and the ActivityOptionsCompat if you are using the Support Library.

API 5+:

For apps targeting API level 5+ there is the Activities overridePendingTransition method. It takes two resource IDs for the incoming and outgoing animations. An id of 0 will disable the animations. Call this immediately after the startActivity call.


startActivity(new Intent(this, MyActivity.class));
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

API 3+:

You can prevent the default animation (Slide in from the right) with the Intent.FLAG_ACTIVITY_NO_ANIMATION flag in your intent.


Intent myIntent = new Intent(context, MyActivity.class);

then in your Activity you simply have to specify your own animation.

This also works for the 1.5 API (Level 3).


You must use OverridePendingTransition method to achieve it, which is in the Activity class. Sample Animations in the apidemos example’s res/anim folder. Check it. More than check the demo in ApiDemos/App/Activity/animation.


public void onResume(){
    // TODO LC: preliminary support for views transitions
    this.overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);


Wrote a tutorial so that you can animate your activity’s in and out,




Jelly Bean adds support for this with the ActivityOptions.makeCustomAnimation() method. Of course, since it’s only on Jelly Bean, it’s pretty much worthless for practical purposes.