overridePendingTransition not working

Viewed 30767

I'm trying to implement a transition in my app but overridePendingTransition(anim, anim) is not working correctly.

  • I have window transitions enabled
  • After debugging the code I can say that the compiler does execute the call but it is NOT shown
  • I have tried calling finish() before overridePendingTransition() this does not seem to have any effect

My code is simple and standard:

Starting the intent and calling overridePendingTransition:

Intent newsIntent = new Intent(ZPFActivity.this, More2013Activity.class);
startActivity(newsIntent);
overridePendingTransition(R.anim.slide_no_move, R.anim.fade);
finish();

The start animation should not do anything only the fade animation should have effect.

slide_no_move XML:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="0%p" android:toYDelta="0%p"
android:duration="500"/>

fade XML:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" 
 android:fillAfter="true">
 <alpha android:fromAlpha="1.0" 
        android:toAlpha="0.0"
        android:duration="500"/>
</set>

EDIT: I forgot to mention the fact that the activities that I start all extend the 'main' activity. Could this be the fact that is causing the problem?

10 Answers

from 6.0 use this method to override the custom animation

ActivityOptions options = ActivityOptions.makeCustomAnimation(context,R.anim.slide_from_right, R.anim.slide_to_left);
Intent intent = new Intent(context, WhichActivityToOpen.class);
context.startActivity(intent, options.toBundle());

The challenge for me was not with execution, but rather proper conceptualization.

The overridePendingTransition method accepts an enter animation and an exit animation.

The trick to conceptualizing these properly is that enter and exit will have different meanings depending on WHERE we call overridePendingTransition:

  • When called from onResume, the current activity is entering and the previous activity (whatever it was) is exiting.
  • When called immediately after startActivity, the next activity (being started) is entering and the current activity is exiting.
  • When called from finish, the next activity (whatever it winds up being) is entering and the current activity is exiting.

Once I understood these rather weird enter/exit rules, I was able to accomplish proper transitions from anywhere to anywhere.

Hope this helps.

Related