2

I have to implement navigation structure like iOS or you can say like browser. where in my application it is like i have 3 tabs and for each tab there is flow of multiple fragments like

Tab 1 --> Fragment 1--> Fragment 2--> Fragment 3

Tab 2 --> Fragment 1--> Fragment 2

Tab 3 --> Fragment 1--> Fragment 2--> Fragment 3--> Fragment 4

And navigation is like when user switches tab then can view last opened Fragment of that Tab and on pressing Back should go back to previously opened Fragment of that Tab. All these Fragments load from single Fragment Activity so what I'm thinking is to manage Navigation manually by creating three different stacks keeping track of opened Fragments in those Tabs.

What i want is a method by which i can bring previously added fragment to front without pop of any other even there are some which added after that fragment. And on back press I'll pop the current fragment and bring in front another previously added fragment according to my own managed stacks.

I searched for method to bring in front previously loaded fragment by tag but they will pop all the fragments loaded after that fragment which is not acceptable for me.

Umar Qureshi
  • 5,985
  • 2
  • 30
  • 40
  • did you find solution for your above scenario? – Khawar Raza Jul 30 '18 at 04:42
  • @KhawarRaza this is similar question with much detailed answers and possible solutions https://stackoverflow.com/questions/6987334/separate-back-stack-for-each-tab-in-android-using-fragments Also this tutorial claims the same thing although i haven't tried it. https://tausiq.wordpress.com/2014/06/06/android-multiple-fragments-stack-in-each-viewpager-tab/ – Umar Qureshi Aug 08 '18 at 14:37

1 Answers1

3

You can try

getSupportFragmentManager().beginTransaction().attach(fragmentA).commit;

or

getSupportFragmentManager().beginTransaction().show(fragmentA).commit;

and hide other fragments you have in your FragmentActivity by looping through all given by

 getSupportFragmentManager().getFragments();
 //This gives list of fragment in stack
Vulcronos
  • 3,428
  • 3
  • 16
  • 24
ellexy
  • 66
  • 1