This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.
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.
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?
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.
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(new Intent(this, MyActivity.class)); overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
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); myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); context.startActivity(myIntent);
then in your Activity you simply have to specify your own animation.
This also works for the 1.5 API (Level 3).
Answered By – whlk