3

i recently faced a pretty strange issue with activity transitions. I'm trying to make a slide in transition with exclusions, which are native status bar, native navigation bar and my custom bottom navigation bar. So i created piece of code based on documentation (link here) which in most cases works pretty well, but sometimes all views in the activity have visibility set as View.INVISIBLE (i know that fact from Layout Inspector).

So, i have activity A and activity B. Then i'm navigating from activity A to B via startActivity(). When i click back on activity B sometimes transition works fine, but in some cases all views on activity A (except bottom navigation bar, which was excluded from transition) are set to View.INVISIBLE

My code:

Activity A :

Intent i = new Intent(this, ActivityB.class);

    Transition slide = new Slide(Gravity.RIGHT);
    slide.excludeTarget(findViewById(R.id.bottom_navigation_bar), true);
    slide.excludeTarget(findViewById(android.R.id.navigationBarBackground), true);
    slide.excludeTarget(findViewById(android.R.id.statusBarBackground), true);
    getWindow().setExitTransition(slide);
    startActivity(i,
            ActivityOptionsCompat.makeSceneTransitionAnimation(this, createPairs()).toBundle());


private Pair[] createPairs() {
    Pair[] pairs = new Pair[2];
    pairs[0] = Pair.create(findViewById(android.R.id.statusBarBackground), Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME);
    pairs[1] = Pair.create(findViewById(android.R.id.navigationBarBackground), Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME);
    return pairs;
}

Activity B:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
    setContentView(R.layout.activity);

    final View decor = getWindow().getDecorView();
    decor.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            decor.getViewTreeObserver().removeOnPreDrawListener(this);
            Transition fade = new Fade();
            fade.excludeTarget(findViewById(R.id.bottom_navigation_bar), true);
            fade.excludeTarget(findViewById(android.R.id.navigationBarBackground), true);
            fade.excludeTarget(findViewById(android.R.id.statusBarBackground), true);
            getWindow().setEnterTransition(fade);
            return true;
        }
    });
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
KaMyLL
  • 969
  • 1
  • 7
  • 13
  • Have you found a solution to this issue? I have the exact same thing on a Moto G with Android 7.0 when I go and come back from 2 different screens. All other screens using the same transitions work fine... – alexbchr Jul 16 '18 at 14:56
  • I just "found" the issue... It seems the transition framework doesn't like transitions that are too long (mine had a duration of 600ms and lowering it to 300ms fixed the issue). Also, I had a lot of issues with slide transitions in the past... Try to switch your transition to a fade transition to see if it fixes your problem. The activity transition framework in general is pretty buggy. If you want to do shared element transitions, I recommend building a one-activity app using fragments, unfortunately... – alexbchr Jul 16 '18 at 15:37
  • So, in my case i've just give up with my code above and some time later i build it again from scratch. Anyways, i discovered that for some unknown reason one of the transitions was paused (TransitionListener.onTransitionPaused()) in his lifecycle when visibility issue apperas. I also faced problems when some activity was calling with Intent.FLAG_ACTIVITY_CLEAR_TOP. – KaMyLL Jul 17 '18 at 07:46
  • Now i have transition defined in xml as transition resource and defined default enter transition in styles.xml. I let Transition Framework play enter transition backwards as exit transition – KaMyLL Jul 17 '18 at 07:57

0 Answers0