android - Fragment Back Button Navigation -


Suppose i have 3 pieces: a, b, c

  1. I Go to - & gt; B
  2. B -> C
  3. C -> B (without pressing the back button)
  4. B -> C (without pressing the back button)
  5. C -> B (without pressing the back button)
  6. B -> C (without pressing the back button)

    Now by pressing the Back Button, Navigation C-> B-> A-> should be there.

    In other words, B-> Regardless of the number of navigation between C and C-> B (without pressing the back button) back to the navigation order should be in C-> B - & gt; A

    assuming that all allowed transit A ​​& lt; - & gt; B & lt; - & gt; C, you can use C-> B using the FragmentManager.popBackStack () method, and whenever you add the transition to return stacks while navigating the B-> C < / p>

    How to make changes here:

      Public Zero Infection FROMATOB () {getSupportFragmentManager () BeginTransaction () .replace (R.id.fragment_container, new fragmentB ()) .addToBackStack (null) .commit (); } Public Zero Infection FROMBToC () {getSupportFragmentManager (). BeginTransaction () .replace (R.id.fragment_container, new FragmentC ()). AddToBackStack (null) .commit (); } Public Zero TansitionFromCToB () {getSupportFragmentManager (). PopBackStack (); } Public Zero Infection FROMBToA () {getSupportFragmentManager (). PopBackStack (); }   

    So when C-> B infection is happening, then you are not actually doing a new infection, you actually just have B-> The C transitions are backwards.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -