To define an animation when the user clicks the back button, you need to override onBackPressed() in Activity and use overridePendingTransition() there:
public void onBackPressed() { super.onBackPressed(); overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right); }
Thus, this animation will be displayed only when you click the "Back" button.
To set up the animation when a new action is opened, you just need to define the animation after calling startActivity() or similar:
startActivity(some_intent); overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
source share