5

I have an activity with a fragment A inside of it. The fragment A have nested fragment B inside of it. I'm switching B with C using following code:

            getChildFragmentManager()
                .beginTransaction()
                .setCustomAnimations(R.anim.move_left_in, R.anim.move_left_out,R.anim.move_right_in, R.anim.move_right_out)
                .replace(R.id.container, fragmentC)
                .addToBackStack("nested")
                .commit();

after that Im doing

        getChildFragmentManager().popBackStack();

what brings me back to fragment B. After that I switch fragment A with fragment D using code

        getSupportFragmentManager()
            .beginTransaction()
            .setCustomAnimations(R.anim.move_up_in, R.anim.move_up_out, R.anim.move_down_in, R.anim.move_down_out)
            .replace(R.id.fragment_holder, fragmentD)
            .addToBackStack("fragments")
            .commit();

and while that animation on A->D transaction is playing, the B plays animation of transaction C->B, and by poping backstack im getting same result, why?

Ivan Mitsura
  • 433
  • 4
  • 15
  • What support libs version do you use? – azizbekian Jun 21 '17 at 11:41
  • I am not getting what you actually want. Can you elaborate a little bit on this part, "and while that animation on A->D transaction is playing, the B plays animation of transaction C->B, and by poping backstack im getting same result, why?"? – Zohaib Hassan Jun 26 '17 at 21:12

2 Answers2

0

When you switch fragment A with fragment D.

The content within fragment A detach from its parent and then transaction A -> D takes place,

Since you have already set animation to your fragments, delay due to those animation is the reason you,see that left out animation in B first, then A -> D animation.

Rachit Solanki
  • 369
  • 6
  • 13
-1

Don't use the getChildFragmentManager(),

Use support fragmnetManager means use getSupportFragmentManager why?

Bcz of nested fragment

I hope your problem is solved with this solution. Thank you:)

Sejal Baraiya
  • 238
  • 2
  • 9
  • Because I've also faced this problem while I'm doing animation with fragments, So, I just change it from child Manager to support manager so after that I get my results which I want. – Sejal Baraiya Jun 27 '17 at 09:27
  • you can check here https://developer.android.com/reference/android/app/FragmentTransaction.html#setCustomAnimations%28int,%20int,%20int,%20int%29 – Sejal Baraiya Jun 27 '17 at 09:29
  • and what about lifecycle? What if you rotate device, is fragment inside fragment recreated properly? – RadekJ Jun 27 '17 at 09:43
  • you can check this , https://stackoverflow.com/questions/8474104/android-fragment-lifecycle-over-orientation-changes – Sejal Baraiya Jun 27 '17 at 10:31