Reputation: 1559
I've implement deeplink with my Jetpack Compose application with the navigation architecture, when the app is close and I click on the deeplink app get open with targeted destination, but when the app is active/open and I click on the deeplink it just open the app with the current app state and not move to the destination. My code structure for handling the navigation is look like this
@Composable
fun MainContent(navController: NavController) {
NavHost(
navController = navController,
startDestination = "home"
) {
// Home Screen
composable("home") { HomeScreen(navController) }
// Example: Profile Screen with deep link
composable(
route = "profile/{userId}",
deepLinks = listOf(navDeepLink {
uriPattern = "https://www.example.com/profile/{userId}"
})
) { backStackEntry ->
val userId = backStackEntry.arguments?.getString("userId")
ProfileScreen(userId)
}
}
}
When I'm not setting any launch mode the deeplink works fine for the both case either the app is open or close but in this case it creates a new instance of the app.
If I specified the launch mode as android:launchMode="singleInstance"
then it prevents the new Instance of the app but it change the behavior of the deeplink as when the app is active/open and I click on deeplink it just open the app with it's current state and if the app is close the it works fine.
Is there something I miss or doing something wrong?
Please help me to implement the deeplink in proper way with Jetpack Compose architecture.
Edited Block for showing the LaunchedEffect Source
LaunchedEffect(deepLinkIntent.value) {
Log.e("DeepLinkNavigation", "Deep Link Data Received: ${deepLinkUri.value}")
deepLinkIntent.value?.let { intent ->
navController.handleDeepLink(intent)
/*val deepLinkRequest = NavDeepLinkRequest.Builder
.fromUri(uri)
.build()
// Attempt to navigate using the deep link request
if (navController.graph.hasDeepLink(deepLinkRequest)) {
navController.handleDeepLink(deepLinkRequest)
}*/
}
/*deepLinkUri.value?.let {
navController.navigate(it.toString())
}*/
}
I tried the commented alternative as well by updating the LaunchedEffect invocation variable as well. Log value printed but navigation not worked.
Thank You!
Upvotes: 2
Views: 112