Jetpack Navigation handling deeplinks manually in onNewIntent
Asked Answered
O

0

5

I'm using Jetpack Navigation. I need to handle deeplinks manually because:

1) Implicit deeplinks are not working properly with android:launchMode="singleTask" Deeplink isn't correctly redirect if the app is already opened

2) I'm passing in my bundles not only simple types but also Parcelables, so I won't have the possibility to pass arguments

I've done proof of concept that is using explicit deeplinkins in onNewintent of my Activity

override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    val data: Uri? = intent?.data

    if(data?.lastPathSegment == "discover") {
        val pendingIntent = NavDeepLinkBuilder(this)
            .setGraph(R.navigation.nav_main)
            .setDestination(R.id.discover_dest)
            .createPendingIntent()

        pendingIntent.send()
    }
}

It works on my phone, but to be honest, it smells. Is it an intended way to use Jetpack Navigation explicit deeplinks? Can I handle manually Jetpack Navigation deeplinks in the nicer way?

Omegaomelet answered 28/4, 2020 at 13:48 Comment(2)
Have you defined better way?Bookmobile
Nope, it stayed that way.Omegaomelet

© 2022 - 2024 — McMap. All rights reserved.