Mahmoo
04/09/2024, 5:46 PMMahmoo
04/09/2024, 5:47 PMMahmoo
04/09/2024, 5:49 PMMahmoo
04/09/2024, 5:51 PMStylianos Gakis
04/09/2024, 5:59 PMMahmoo
04/09/2024, 6:04 PMandroidx.navigation:navigation-fragment-ktx (for fragment navigation)
androidx.navigation:navigation-ui-ktx
androidx.navigation:navigation-runtime-ktx
androidx.navigation:navigation-compose
I've been using theseMahmoo
04/09/2024, 6:05 PMStylianos Gakis
04/09/2024, 6:06 PMNavHost() {
navigation("graphA", startRoute = "...") {
composable() {...}
}
navigation("graphB", startRoute = "...") {
composable() {...}
}
navigation("graphC", startRoute = "...") {
composable() {...}
}
navigation("graphD", startRoute = "...") {
composable() {...}
}
}
Mahmoo
04/09/2024, 6:06 PMStylianos Gakis
04/09/2024, 6:06 PMStylianos Gakis
04/09/2024, 6:07 PMcomposable(
route = "...",
deepLinks = listOf(
navDeepLink { uriPattern = "https://..../...." },
),
) {...}
Mahmoo
04/09/2024, 6:09 PMMahmoo
04/09/2024, 6:09 PMStylianos Gakis
04/09/2024, 6:11 PMStylianos Gakis
04/09/2024, 6:16 PMcontractId
placeholder here.
Then how it is turned in to this class here
The type-safety comes from using navigation-compose-typed. But the official implementation is coming with type safe impl soon too.Mahmoo
04/09/2024, 6:18 PMStylianos Gakis
04/09/2024, 6:19 PMStylianos Gakis
04/09/2024, 6:43 PMMahmoo
04/11/2024, 4:41 PMMahmoo
04/11/2024, 4:41 PMStylianos Gakis
04/11/2024, 4:43 PMMahmoo
04/11/2024, 4:45 PMval intent by mainActivityViewModel.intent.collectAsState()
LaunchedEffect(key1 = intent) {
Log.d("IntentReceived1", "$intent")
Log.d("IntentReceived2", "${intent?.data}")
navController.handleDeepLink(intent)
}
Mahmoo
04/11/2024, 4:46 PMviewModel.setIntent(intent)
I am setting this intent from activity's onCreate and from onNewIntentMahmoo
04/11/2024, 4:46 PMfun setIntent(intent: Intent?) {
viewModelScope.launch {
_intent.emit(intent)
}
}
like this is viewModelStylianos Gakis
04/11/2024, 4:46 PMStylianos Gakis
04/11/2024, 4:47 PMStylianos Gakis
04/11/2024, 4:48 PMrememberNavController
will actually do the forwarding of the intent to the NavController, to be more preciseStylianos Gakis
04/11/2024, 4:49 PMonNewIntent
override eitherMahmoo
04/11/2024, 4:51 PMStylianos Gakis
04/11/2024, 4:55 PMonNewIntent()
?Mahmoo
04/11/2024, 5:02 PMStylianos Gakis
04/11/2024, 6:27 PMMahmoo
04/11/2024, 6:45 PMStylianos Gakis
04/11/2024, 6:52 PMonNewIntent()
function and call it from your activity. Then in your fragment pass the intent into the NavController.
With all that said, you may not actually want to change the launchMode, I don't know what your app is for but most of the time that is just the correct thing to doMahmoo
04/11/2024, 7:33 PMStylianos Gakis
04/11/2024, 7:37 PMMahmoo
04/11/2024, 7:43 PMStylianos Gakis
04/11/2024, 8:00 PMMahmoo
04/12/2024, 10:06 PMMahmoo
04/12/2024, 10:07 PMMahmoo
04/12/2024, 10:10 PMStylianos Gakis
04/12/2024, 10:14 PMmy app gets recreated when navigating using deeplinksWhat do you mean by this? Through normal behavior if you are deep linked into your app from inside another app you may have 2 instances of your app running at the same time, is that what you were experiencing here? Purely as a coincidence, I was showing an example of this here https://kotlinlang.slack.com/archives/C051P2HUVKP/p1712603841054079?thread_ts=1711657801.535509&cid=C051P2HUVKP at the last ~5 seconds of this video
Mahmoo
04/12/2024, 10:20 PMStylianos Gakis
04/12/2024, 10:26 PM