我对这样的容器有活动:
<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工具栏的“向上”按钮时,我的图形基本上是从头开始的?我希望这样的操作会关闭活动。