简体   繁体   English

如果使用导航架构组件已经存在,如何避免将片段添加到后台堆栈?

[英]How to avoid adding a fragment to the backstack if it already exists using Navigation Architecture Component?

I am using navigation component so I'm not using a FragmentManager.我正在使用导航组件,所以我没有使用 FragmentManager。 Let's say I have fragments A, B.假设我有片段 A、B。

If user navigates A -> B -> A -> B and then presses the back button I want the backstack to just be A instead of A -> B -> A. In other words don't add a Fragment if it already exists in the backstack.如果用户导航 A -> B -> A -> B 然后按下后退按钮,我希望 backstack 只是 A 而不是 A -> B -> A。换句话说,如果片段已经存在,则不要添加它在后台。 Is this possible without using FragmentManager?这可能不使用 FragmentManager 吗?

Yes you need to use setPopUpTo是的,您需要使用setPopUpTo

Here is a good article to help you out这是一篇很好的文章,可以帮助您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在导航架构组件中手动将片段添加到后台堆栈中 - Adding fragment manually into the backstack in Navigation Architecture Component 禁用在Navigation Architecture Component中将片段添加到backstack - Disable adding fragment to backstack in Navigation Architecture Component 如何使用导航架构组件避免片段重新创建? - How to avoid fragment recreation using navigation architecture component? Android导航组件如何打开新片段而不将其添加到backStack? - Android Navigation Component how to open new fragment without adding it to backStack? 使用导航组件从 Backstack 中删除片段 - Unclude fragment from Backstack using Navigation component 避免使用导航架构组件弹回特定片段 - Avoid to popback to specific fragment with Navigation Architecture Component 导航架构组件 - BottomNavigationView 避免片段重新加载 - Navigation Architecture Component - BottomNavigationView avoid fragment reloading Android导航架构组件避免了Fragment娱乐 - Android Navigation Architecture component avoid Fragment recreation 使用导航组件删除后台堆栈中的片段 - Remove fragment in backstack with navigation component 如何从片段导航组件的后台堆栈中仅删除一个片段? - How to remove only one fragment from backstack in fragment navigation component?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM