How to provide animation when calling another activity in Android?( from Stack overflow)

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?

Hope to get a quick response.

Regards

 

Answer 1

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

i.e.:

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.


Answer2(This is better)

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

Intent intent = new Intent();intent.setComponent(new ComponentName("com.jason.recite", ProjectInfoActivity.class.getName()));startActivity(intent);ProjectActivity.this.overridePendingTransition(R.anim.fade, R.anim.hold);

你可能感兴趣的:(animation)