5

For my live wallpaper I want to change the exit animation for the settings activity. By default, when exiting the activity, it simultaniously scales down to the center and fades out. I want it to just fade out, with no resizing involved.

I've tried defining my own animation settings in styles.xml. Setting android:windowExitAnimation to @android:anim/fade_out does not seem to do what I want. The animation still scales down before it is faded out. I've tried countless of other animation settings, such as android:activityCloseExitAnimation, but none of them seem to get rid of the resizing behaviour I explained above.

Also, overridePendingTransition(0, R.anim.abc_fade_out); has the same result: the activity still scales down when exiting.

Is there any way to override this default animation behaviour, so that the exit animation doesn't involve resizing?

If not, is it possible to entirely remove the exit animation, so that the application dissapears instantly?

Rudey
  • 4,717
  • 4
  • 42
  • 84

1 Answers1

18

You should try to override the finish method inside your Activity as follows:

@Override
public void finish() {
    super.finish();
    overridePendingTransition(0, R.anim.abc_fade_out);
}  
Blo
  • 11,903
  • 5
  • 45
  • 99
  • 1
    That worked, thanks! I still have one question though. What if I wanted to set the **enter** animation using `overridePendingTransition`? Where should I do that? – Rudey Apr 16 '14 at 20:11
  • Using this method, I think you can try to call it in onCreate or onStart (see the [lifecycle](http://developer.android.com/reference/android/app/Activity.html)), but I don't know if you will have the expected result. However, you could also use a [custom animation](http://stackoverflow.com/a/4940610/2668136) from your style. @RuudLenders – Blo Apr 16 '14 at 20:50
  • 1
    Currently I'm using a *custom animation* for the **enter** animation, and the *code* you wrote above for the **exit** animations. It works like I want it to, but it feels wierd using different methods for the enter/exit animation. I will try overriding `onCreate` or `onStart`. – Rudey Apr 16 '14 at 21:40
  • 1
    You were right, the enter animation can be overridden in `onCreate`. – Rudey Apr 20 '14 at 10:52
  • Yes, good to know. You can also do the same in `onResume` method. Good coding. – Blo Apr 20 '14 at 10:56