PopBackStack但保留android中的第一个片段 [英] PopBackStack but keep the first fragment in android
本文介绍了PopBackStack但保留android中的第一个片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在处理fragment事务,backstack是这样的:
I am working on fragment transaction, and the backstack is like this:
fragA => fragB => fragC => fragD
我想从fragD回来后回到fragA
I would like to return to fragA after back fromn the fragD
fragD => onBackPress => fragA
所以,我尝试了如下代码:
So, I tried code like:
getChildFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
但是它清除了所有的 backstack ,我怎样才能将第一个片段保留在 backstack 中?非常感谢
but it clear all the backstack , how can I keep the first fragment in the backstack? Thanks a lot
推荐答案
例如您可以执行以下操作:
E.g. you can do following:
- 在不将其添加到 backStack 的情况下添加 fragA.所以它总是在
活动,并且不会对后退按钮做出反应. - 当您打开 fragD 时,您应该清除片段 BackStack.所以当你从 D frag 按下后退按钮时,你会回到 A.
- add fragA without adding it to backStack. So it always be in
activity, and won't react on back button. - when you open fragD you should clear fragment BackStack. So when you press back button from D frag you go back to A.
附言还有其他方法可以做你想做的事.这取决于...
P.S. There are other ways how to do what you want. It depends...
这篇关于PopBackStack但保留android中的第一个片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文