20

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?

Tim Kranen
  • 4,202
  • 4
  • 26
  • 49

10 Answers10

30

Try to call the pendingTransition after calling finish(), like this:

Intent newsIntent = new Intent(ZPFActivity.this, More2013Activity.class);
startActivity(newsIntent);
finish();
overridePendingTransition(R.anim.slide_no_move, R.anim.fade);
Damien R.
  • 3,383
  • 1
  • 21
  • 32
27

If you activate usb debugging mode, it can disable the transitions effects. Enter Developer options (where you activated debugging mode), find the user's interface section, check if the animation's transition scale have the animations disabled. If so, set it to .5x. Done!

17

If you are using android version >= 21 then make the android:windowActivityTransitions attribute to true in the style.xml file in the values-v21 folder as follows.

   <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

       <item name="android:windowActivityTransitions">true</item>

   </style>
King King
  • 61,710
  • 16
  • 105
  • 130
Prasad
  • 3,462
  • 1
  • 23
  • 28
15

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());
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
koteswara D K
  • 628
  • 2
  • 9
  • 19
14

Try using this :

    public class More2013Activity extends Activity{
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          overridePendingTransition(R.anim. slide_no_move, R.anim.fade_in);
          setContentView(R.layout.more_activity)
      }
    }

instead of your code.

hardartcore
  • 16,886
  • 12
  • 75
  • 101
  • Just tried to but it didn't work. Please check my edit I forgot to mention the fact that all activities implement the 'main' activity. – Tim Kranen Dec 23 '13 at 14:14
  • you can test by making your `More2013Activity` to extends `Activity`, not your main one to see if that's the problem. – hardartcore Dec 23 '13 at 14:22
6

Go in your device Developer Options, There are three further options windows animation scale, Transition Animation scale and Animation duration scale. Make sure all are not off. This is one of the reason I came across.

user1154390
  • 2,331
  • 3
  • 25
  • 32
  • This post was already answered. I had already verified the fact that these were turned on. It was a device specific problem. – Tim Kranen Mar 17 '15 at 13:29
  • @Tim Kranen, It is not device specific problem for your kind information. Don't miss lead others. It is not my mistake if you picked up wrong answer. – user1154390 Mar 18 '15 at 12:34
  • But this problem WAS device specific. I have tried your solution too, it didn't help. The device simply didn't support these animations. – Tim Kranen Mar 18 '15 at 14:51
4

I know this is an old post, but I saw it and felt obligated to answer it:

It was a very obscure problem, and it was device related. I was using an iOcean X7 at the time. Later I found out that this Phone was not able to play animations. For some it did not play animations on ANY app.

Tim Kranen
  • 4,202
  • 4
  • 26
  • 49
2

please check your device is in power saving mode. in power saving mode animations will not work.

Anshad Ali KM
  • 1,207
  • 9
  • 8
  • 3
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Vality Aug 20 '14 at 13:40
  • 1
    I had the same problem, I have searched many times for this question, but i didnt checked whether my phone is in power saving mode, In power saving mode overridePendingTransition will not work, i have changed the mode to normal, now it is working, – Anshad Ali KM Aug 21 '14 at 09:41
2

Probably you are using overridePendingTransition(anim, anim) in your onPause() method too. I had the same problem but I solve it by a tiny trick.

1: Define a boolean in your class before onCreate() method

private boolean pendingTransaction = true;

@Override
protected void onCreate(Bundle savedInstanceState) {...

2: Set pendingTransaction to false when you you use startActivity();

Intent newsIntent = newIntent(ZPFActivity.this,More2013Activity.class);         
 pendingTransaction = false;        
 startActivity(newsIntent);        
 overridePendingTransition(R.anim.slide_no_move, R.anim.fade);

3: Override the onPause() method by doing this.

@Override
protected void onPause() {
    if (pendingTransaction) {
        overridePendingTransition(R.anim.slide_no_move, R.anim.fade);
    }
    super.onPause();
}

4: Override the onResume() method by doing this.

@Override
protected void onResume() {
    super.onResume();
    pendingTransaction = true;
}
Community
  • 1
  • 1
0

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.

rmirabelle
  • 6,268
  • 7
  • 45
  • 42