How to recreate singleTop behavior when using navigation component's deep links?
I'm using Jetpack Navigation and I'm currently trying to implement notification clicks. One of the fragments is used to play music. When you background the app, a notification is displayed and music continues to play. When I click the notification I would like to go back to the fragment with the playback. I would like to mimic singleTop
behavior.
To handle notifcation clicks I'm using an explicit deep link (PendingIntent
with navigation graph):
val pendingIntent = NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.music)
.setArguments(...)
.createPendingIntent()
Unfortunately, it clears the task back stack and replaces it with the deep link destination. How can I prevent this behavior? I know there is NavOptions#shouldLaunchSingleTop
but I see no way to use it with the PendingIntent
and NavDeepLinkBuilder
. Is it possible to launch deep link with NavOptions?