android - Is there any other way to close Fragment besides popBackStack()?
滿天的星座
滿天的星座 2017-05-16 13:35:12
0
2
727

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);    //会被执行?
滿天的星座
滿天的星座

reply all(2)
Peter_Zhu

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

迷茫

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template