I haave couple of issues with deep linking with compose navigation.
- When deeplink is connected to a screen that is in the main Graph it works just fine if the application is cloed, but if its already open the app does not navigate to the target screen. i set
android:launchMode="singleTask"
in the manifest. - When i try to open a deep link that is connected to a nested graph i get an exception
IllegalArgumentException: navigation destination is not a direct child of this NavGraph
I'm not sure how to aproach these issues, Can anyone help me out?
Here are sample of my code:
Manifest
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:screenOrientation="userPortrait"
tools:ignore="LockedOrientationActivity"
android:launchMode="singleTop"
android:theme="@style/Theme.App.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="example.com"
android:scheme="https" />
</intent-filter>
</activity>
Navigation for destination in home graph
composable(
route = NavigationScreen.Item.route,
deepLinks = listOf(navDeepLink {
uriPattern = "${BuildConfig.DEEP_LINK_URI}/items/{itemId}"
}),
enterTransition = flowParentOnTabEnterTransition(),
exitTransition = flowParentOnTabExitTransition(),
popEnterTransition = itemPopEnterTransition(),
popExitTransition = itemPopExitTransition()
) {
it.arguments?.getString("itemId")?.let { itemId ->
ItemScreen(navController, itemId)
}
}
Navigation for destination in nested graph
composable(
route = NavigationSearch.Tag.route,
deepLinks = listOf(navDeepLink { uriPattern = "${BuildConfig.DEEP_LINK_URI}/tag/{id}" }),
arguments = listOf(
navArgument(ARG_TAG_ID) {
type = NavType.StringType
}
),
enterTransition = simpleEnterTransition(),
exitTransition = simpleExitTransition(),
popEnterTransition = simplePopEnterTransition(),
popExitTransition = simplePopExitTransition()
) {
val tagId = it.arguments?.getString(ARG_TAG_ID)
TagScreen(navController, tagId)
}