- 2020/11/10 更新
この問題について修正されており次のバージョンである 2.3.2 で修正されるようです
https://android-review.googlesource.com/c/platform/frameworks/support/+/1489583/
AndroidX の Navigation 2.3.1 で MenuItem#onNavDestinationSelected
を使用して Activity へ遷移させると遷移が正しくできない問題に遭遇しました。
Fragment への遷移ではこの現象は発生しません。
Workaround
Issue Tracker に報告したところ、バグ扱いになったのでライブラリ側で対応してくれるのを待ってもいいかもしれません。
https://issuetracker.google.com/issues/171364502
Activity への遷移の時は navigate
を使用するようにすれば回避することができます。
override fun onOptionsItemSelected(item: MenuItem): Boolean {
val navController = findNavController(R.id.nav_host_fragment)
if (navController.currentDestination?.parent?.findNode(item.itemId) is ActivityNavigator.Destination) {
navController.navigate(item.itemId)
return true
}
return item.onNavDestinationSelected(navController) ||
super.onOptionsItemSelected(item)
}