I am creating an explicit deeplink to a fragment in my app (Navigation component). This is how I am currently doing it:
val args = bundleOf(
"roomId" to roomId,
"receiver" to receiver
)
return NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph_home)
.addDestination(R.id.navigation_chat_private)
.setArguments(args)
.createPendingIntent()
The arguments are defined in the nav_graph like this:
<argument android:name="roomId" app:argType="string" />
<argument android:name="receiver" app:argType="integer" />
This works without issue. But I can't help but wonder if there is a way to avoid hardcoding the parameter names twice. I feel like there HAS to be a better way. Something along the lines of:
val chatArgs = NavigationChatPrivateArgs(roomId,receiver)
return NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph_home)
.addDestination(R.id.navigation_chat_private)
.setArguments(chatArgs.toBundle())
.createPendingIntent()
But there is no such constructor in the generated safeArgs class. I also tried calling the empty constructor and then setting the values, but the args are val
s, so cannot be reassigned. Is anybody aware of an elegant way to do this?