我在这样的容器中活动:
<fragment
android:id="@+id/nav_host_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/my-graph-name" />
我的活动也配置如下:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
NavigationUI.setupActionBarWithNavController(
this,
findNavController(R.id.nav_host_container)
)
}
override fun onSupportNavigateUp(): Boolean {
return findNavController(R.id.nav_host_container).navigateUp()
}
我的图形的startDestination有一个动作片段:
<action
android:id="@+id/action1"
app:popUpTo="@+id/my1stFragment"
app:popUpToInclusive="true"
app:destination="@+id/my2ndFragment" />
问:为什么当我点击my2ndfragment工具栏的“向上”按钮时,我的图形基本上是从头开始的?我希望这样的操作会关闭活动。
答案 0 :(得分:0)
如果用户位于应用程序的启动目标位置,则不会显示“向上”按钮,因为“向上”按钮永远不会退出应用程序。但是,显示了“后退”按钮,并退出了应用程序。
使用其他应用程序的任务上的深层链接启动您的应用程序时,Up会将用户转换回您的应用程序的任务,并通过模拟的反向堆栈将其转移到触发深层链接的应用程序。但是,“后退”按钮确实会将您带回到另一个应用程序。