I've found the issue but i can't understand why it is happening.
In the MainActivity i choose the startDestination:
navController.graph = navController.navInflater.inflate(R.navigation.navigation)
.apply {
runBlocking {
startDestination =
if (viewModel.userIsLoggedIn()) R.id.mainFragment
else R.id.LoginFragment
}
}
Then when i send a notification i use this as the pendingtIntent
val pendintIntent = NavDeepLinkBuilder(this)
.setDestination(R.id.someFragment)
.setGraph(R.navigation.nav_graph)
.setComponentName(MainActivity::class.java)
.createTaskStackBuilder().getPendingIntent(0, PendingIntent.FLAG_IMMUTABLE)
This works fine, when i clicked on the notification it navigates to the desired fragment, but it creates that fragment twice and i don't know why.
If i removed the startDestination chooser in the MainActivity it only creates one instace of the fragment.
I've also tried but didn't worked.
val pendingItent =
...
.setGraph(navController.graph)
...
Any ideas why is this happening and how can i solve this?