我使用导航组件在片段之间导航。
在主要活动中初始化导航:
val navHostFragment = NavHostFragment.create(R.navigation.nav_graph)
supportFragmentManager
.beginTransaction()
.replace(R.id.container, navHostFragment)
.commit()
Run Code Online (Sandbox Code Playgroud)
导航到飞溅片段中的另一个片段:
findNavController().navigate(SplashFragmentDirections.actionSplashFragmentToHomeActivity())
Run Code Online (Sandbox Code Playgroud)
在飞溅中我进行身份验证,需要一些时间,身份验证后我导航到主页片段。如果我最小化启动片段中的应用程序(按主页按钮),则导航()不起作用,当我再次打开应用程序时,它仍保留在启动片段中
在控制台中:
NavController: Ignoring popBackStack to destination my.app/homeFragment as it was not found on the current back stack
FragmentNavigator: Ignoring navigate() call: FragmentManager has already saved its state
Run Code Online (Sandbox Code Playgroud)