Marie M.
Marie M.

Reputation: 170

Android FragmentManager: Custom animation shows wrong exit fragment

I'm using the SupportFragmentManager to navigate between different fragments (let's call them A, B, C, D for simplicity). The navigation itself works correctly. The animation works only correctly considering the entering fragments. My code is basically the same for navigating between all fragments:

activity?.supportFragmentManager?.commit {
                    setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right)
                    replace(R.id.myNavHostFragment, BFragment())
                }

The navigation is only linear, so I navigate from A -> B, B -> C, and C -> D.

The problem is: only the animation of A -> B works correctly. For all others, during the animation, the wrong 'old' (exit) fragment A is shown in background, while the new one slides in.

So this means:

As you can see, I do not add fragments to the backstack. I really can't figure out why Fragment A is always shown during the animation, even if it should be a different one.

In a nutshell: the animation shows always the first fragment (A) as exit fragment, while it should be the previous one instead.

Upvotes: -1

Views: 114

Answers (1)

SVK
SVK

Reputation: 756

Please check your navigation graph and re-visit all the below attributes shown in below image.
Open your own navigation_graph.xml and then click on Design tab. You will see below attribute(as shown in image) when you click on navigation direction.

Also, Animation has nothing to do with the back stack of your app.

You need to check Pop Behavior and Launch Options

Also please see if you have set any Flag's incorrectly in your code. For e.g. FLAG like FLAG_ACTIVITY_CLEAR_TOP

And finally please thoroughly go through this Article

Navigation Graph in Android Studio

Upvotes: 1

Related Questions