Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raxhaxor/b48a5dcd30a88508bba8c816316aade4 to your computer and use it in GitHub Desktop.
Save raxhaxor/b48a5dcd30a88508bba8c816316aade4 to your computer and use it in GitHub Desktop.
Set startDestination & startDestinationArgs in Navigation component programmatically
val finalHost = navHostFragment as NavHostFragment
val navController = finalHost.navController
val graphInflater = navController.navInflater
val navGraph = graphInflater.inflate(R.navigation.my_subscription_nav_graph).apply {
val destination = if (isBeautySubscription) R.id.beautyServiceSubscriptionDetailsFragment else R.id.activeSubscriptionDetailFragment
startDestination = destination
}
navController.setGraph(navGraph, Bundle().apply {
putString("subscriptionId", intent.getStringExtra("subscriptionId"))
})
supportFragmentManager.beginTransaction()
.replace(R.id.navHostFragment, finalHost)
.setPrimaryNavigationFragment(finalHost)
.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment