0

I have a navigation graph that looks like this:

Fragment 1 --> (Action A) --> DialogFragment 1 --> (Action B) --> Fragment 2

When performing Action B, we unfortunately don't switch directly directly to Fragment 2. Instead, the screen first shows Fragment 1 for a short moment (0.1 seconds or so), which looks very bad for my flow.

I'm using the feature as suggested in this answer, with navigation-fragment version 2.1.0-rc01, which is the most stable version currently available with the <dialog> feature.

Hibuki
  • 544
  • 3
  • 14

1 Answers1

1

TL;DR: Override the dismiss() function of your DialogFragment:

public class MyDialogFragment extends DialogFragment {
    ...
    @Override
    public void dismiss() {
        getFragmentManager().executePendingTransactions();
        getView().post(() -> super.dismiss());
    }
}

This is just a patch until the feature will be fixed, it works for me, please update especially if it doesn't work for you.

The problem is some race between:

  1. The fragment transaction to Fragment 2 (which is correctly called first in Navigation.java, see NavDestination newDest = navigator.navigate(..., but probably takes a moment in the looper queue before being executed )

And

  1. The Dialog dismiss() (which is correctly called only afterwards, but happens first)
Hibuki
  • 544
  • 3
  • 14