Home  >  Q&A  >  body text

android - Is there any other way to close Fragment besides popBackStack()?

In addition to popBackStack() and popBackStackImmediate(), is there any other way to specify to close the fragment in the manager?

Using fragment to manage the interface, I encountered a problem.
I opened interface B from interface A, and then interface B opened interface C. At this time, I need to return directly from interface C to A. interface,

At the beginning, I tried to popBackStack() when opening interface C, but an exception was thrown

. . It suddenly occurred to me while typing that I could use popBackStack(A's Tag, 0) to directly remove B and C. But I still want to ask if there are other ways to manage them?

I also want to ask popBackStackImmediate() Is it possible that it will not be executed?

 manager.popBackStackImmediate(tag, 1);//不会被执行?

 manager.popBackStack(tag, 1);    //会被执行?
滿天的星座滿天的星座2730 days ago710

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-05-16 13:37:12

    The questioner did not read the API documentation carefully. Before reading the documentation, install Google Translate

    popBackStack()这样的函数都是跟后退栈有关的调用, FragmentYou don’t need to push to the back stack. If you need to respond to the back button, you need to manage the Fragment’s back stack.

    You can refer to how the following classes manage Fragments:

    • FragmentPagerAdapter

    • FragmentStatePagerAdapter

    reply
    0
  • 迷茫

    迷茫2017-05-16 13:37:12

    If you are in an activity, you can use the methods provided by add show hide等一系列getSupportFragmentManager to manage your frgament

    reply
    0
  • Cancelreply