5

I am creating an app where almost all of the animations are fades. For a few of the pages, elements will dynamically appear / disappear off the screen, and all the fading is quite natural (white background for the app). However, when I transition between Activities, the app fades to black before fading back into the next Activity. Since all the backgrounds are the same color, I was wondering if there was a way to avoid this, so that the background constantly remains the same color, and only the elements on it seem to fade as the app state changes.

I use the following code for my transitions:

Intent intent = new Intent(this, NextActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

Sometimes without the finish(), as necessary. I've looked into this briefly, and the problem other people seem to have is with a long lasting black screen that is associated with NextActivity having a computationally intensive onCreate(). This is not the case for me. The onCreate() methods do little in terms of computing, merely define some listeners. All intense logic is offloaded to threads. It is quite literally a UI problem for me that I am trying to find a work around for.

mike
  • 1,318
  • 3
  • 21
  • 41
  • Try adding this `getWindow().setBackgroundDrawableResource(R.drawable.my_drawable);` before `overridePendingTransition(R.anim.fade_in, R.anim.fade_out);` -- and, of course, make a non-black drawable for it to reference. – JASON G PETERSON Dec 26 '14 at 05:44
  • Didn't work, unfortunately – mike Dec 26 '14 at 05:50
  • You might try setting either of these, or both, in your styles rather than trying it programatically: http://stackoverflow.com/questions/26266221/difference-between-androidwindowbackground-and-androidcolorbackground – JASON G PETERSON Dec 26 '14 at 06:05

2 Answers2

2

I found that setting android:zAdjustment="top" on the fade out animation made the black screen in-between go away.

See sample XML in this answer: https://stackoverflow.com/a/9150436/1481500

Community
  • 1
  • 1
kos
  • 1,770
  • 2
  • 19
  • 41
1

I recommend people looking at this question to check out at Taig's answer in this other question. Much simpler solution for people that want a nice fade transition:

https://stackoverflow.com/a/34024547/8050896

The gist of it is to only set a fade-out animation between the transition to avoid seeing the launcher background when both activities fade. So the second activity doesn't actually have an animation.

startActivity( ... );
finish();
overridePendingTransition(0, R.anim.screen_splash_fade_out); // only a fade out animation
P Fuster
  • 2,224
  • 1
  • 20
  • 30