- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个简单的 ToDo 应用程序并检查导航方法以从 AddTask fragment 返回到我的 mainFragment。我发现我可以使用 navigateUp() 和 popBackStack() 返回,但我不明白其中的区别。
当我使用这个时:
Navigation.findNavController(it).navigateUp()
或这个:
Navigation.findNavController(it).popBackStack()
我回到 mainFragment,我认为 addTaskFragment 是从堆栈中弹出的,所以有人可以解释一下吗?
最佳答案
抱歉,(编辑:以前)接受的答案是绝对错误的,navigateUp()
如果有的话,也会从 backstack 中弹出顶部的 fragment 。
初学者:如果您从应用程序中到达当前目的地,它们的行为完全相同。
仅当您使用来自不同应用的深层链接到达当前目的地时,它们的行为才会有所不同:navigateUp()
将离开您的应用并返回到导航到您应用中的深层链接的应用。popBackStack()
将尝试在您的 backstack 中返回一步,如果没有 backstack 条目,则不会执行任何操作。
您可以阅读以下内容的差异:
https://developer.android.com/reference/androidx/navigation/NavController#navigateUp()
navigateUp()Attempts to navigate up in the navigation hierarchy. Suitable for whenthe user presses the "Up" button marked with a left (or start)-facingarrow in the upper left (or starting) corner of the app UI.
The intended behavior of Up differs from Back when the user did notreach the current destination from the application's own task. e.g. ifthe user is viewing a document or link in the current app in anactivity hosted on another app's task where the user clicked the link.In this case the current activity (determined by the context used tocreate this NavController) will be finished and the user will be takento an appropriate destination in this app on its own task.
popBackStack()Attempts to pop the controller's back stack. Analogous to when theuser presses the system Back button when the associated navigationhost has focus.
关于android - navigateUp() 和 popBackStack() 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67245601/
我正在使用新的 AndroidX 导航框架。 我有几个 fragment 都链接在导航链中。 fragment A --> fragment B --> fragment C FragmentC 有一
我正在创建一个简单的 ToDo 应用程序并检查导航方法以从 AddTask fragment 返回到我的 mainFragment。我发现我可以使用 navigateUp() 和 popBackSta
我在 Kotlin 中创建了一个新的 Android 项目。我还使用向导创建了一个新的抽屉导航 Activity 。一如既往,没有什么是开箱即用的。 以下行显示了编译错误: val navContro
I found the question but does not have solution in code 我想在发生背压/手动后退时获得数据。我正在使用 navigateUp() 返回。如何将数
当 NavigationView 与 DrawLayout 和 ActionBar 一起使用时,jetpack 提供了一些强大的便捷方法来 Hook 一切都放在一起,以便这些项目更容易实现。 Navi
当通过navigateUp()返回IpFragment时,它有时是空白的,而它应该显示几个简单的 TextView 。有时它会正确渲染,但当它失败时,唯一的错误似乎无关。 返回时显示为空白的 frag
我正在开发一个安卓应用程序。在此应用程序中,我有 3 个 Activity ,一个是 Title Activity,另一个是 Subtitle Activity,另一个是 detail Activit
我是一名优秀的程序员,十分优秀!