PopBackStack但保持Android的第一个片段 [英] PopBackStack but keep the first fragment in android
本文介绍了PopBackStack但保持Android的第一个片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的工作片段事务,而backstack是这样的:
I am working on fragment transaction, and the backstack is like this:
fragA => fragB => fragC => fragD
我想回fromn的fragD后返回弗拉加
I would like to return to fragA after back fromn the fragD
fragD => onBackPress => fragA
所以,我试过code,如:
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。因此,它永远是结果
活性,并且不会对后退按钮反应。 - 当你打开fragD你应该明确的片段BackStack 。所以,当你从属性同好会preSS后退按钮你回到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。还有其他的方法怎么做你想要的。这取决于...
P.S. There are other ways how to do what you want. It depends...
这篇关于PopBackStack但保持Android的第一个片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文