Fragments in backStack

1 answer

I have ViewPager that has 3 tabs. Tab(3) includes 2 fragments (A) --> (B).

Tab(1) Tab(2) Tab(3) --> (B) --> (C) 

The way I replace fragments in Tab(3):

FragmentTransaction trans = getActivity().getSupportFragmentManager().beginTransaction();             trans.replace(R.id.B_container, new FragmentC().newInstance(), "C");             trans.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);             trans.addToBackStack("B->C");             trans.commit(); 

When I'm in (B) and I'm hitting a button it takes me straight to Tab(3), skipping (A). Here is the code from button in (B):

FragmentManager fm = getActivity().getSupportFragmentManager();             for(int i = 0; i < fm.getBackStackEntryCount(); ++i) {                 fm.popBackStack();             } 

Everything works good. The problem is when I'm in (B) but then I go to Tab(1) or Tab(2) and hit the button after it doesn't work. Please let me know what I'm doing wrong. Thank you.

//======================================================================

I tried to replace etActivity().getSupportFragmentManager() with getChildFragmentMaganer(). Since the regular way of popBackStack() wasn't working anymore I had to modify it. Now it works and I have the same problem tho.

FragmentManager fm = getActivity().getSupportFragmentManager();             for (Fragment frag : fm.getFragments()) {                     FragmentManager childFm = frag.getChildFragmentManager();                     if (childFm.getBackStackEntryCount() > 0) {                         childFm.popBackStack();                     }                 }             } 

All answers to this question, which has the identifier 61238987

The best answer:

Try using getChildFragmentManager() to get your fragment manager. From my experience, when i'm inside a fragment and i try to place another fragment inside it, I use getChildFragmentManager.

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data