Disable fragment back stack animations - Android
<p>How are you able to disable all fragment animations including the exit animation when clearing the back stack, currently I am using the following code but it doesn't seem to stop the animation exiting the screen, rather it only stops the animation of the new fragment entering the screen.</p>

<p>The code that I'm using is as follows:</p>

<p><strong>Menu Fragment - code used to clear back stack</strong></p>

<pre><code>    private void clearBackStack() {
        FragmentUtils.sDisableFragmentAnimations = true;
        getSupportFragmentManager().popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        FragmentUtils.sDisableFragmentAnimations = false;
    }
</code></pre>

<p><strong>Fragment Utils Class:</strong></p>

<pre><code>public class FragmentUtils {
    public static boolean sDisableFragmentAnimations = false;
}
</code></pre>

<p><strong>All fragments have this:</strong></p>

<pre><code>@Override
public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
    if (FragmentUtils.sDisableFragmentAnimations) {
        Animation a = new Animation() {};
        a.setDuration(0);
        return a;
    }
    return super.onCreateAnimation(transit, enter, nextAnim);
}
</code></pre>

<p><strong>Navigation menu code (where I want to disable the animations)</strong></p>

<pre><code>    bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.action_events:

                    replaceFragment(new MainFragment());

                    break;
                case R.id.action_promotions:

                    replaceFragment(new MainFragment());
                    break;

                case R.id.action_menu:

                    clearBackStack();
                    replaceFragment(new MenuFragment());
                    break;

            }
            return true;
        }
    });
</code></pre>