在导航组件中,如何检测 fragment 是否从弹出事件中被带到前面?
我从 A 到 B,现在我使用返回键关闭 B,它返回到 A,现在在 A(在 onViewCreated 事件中)我想检测它来自 B。
最佳答案
如果我们使用单个 NavController。
findNavController((R.id.nav_host_fragment)
.addOnDestinationChangedListener{ hostController, destination, _ ->
val push = currentBackStackSize < hostController.bacStack.size // else pop
// Then save current backstack size
}
这个解决方案可能并不总是正确的,但目前我想不出一个边缘案例。请随时纠正我。
关于android - 检测导航组件中的弹出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55789935/