Jetpack Navigation handling deeplinks manually in onNewIntent

蹲街弑〆低调 提交于 2021-01-24 08:15:19

问题


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?

来源:https://stackoverflow.com/questions/61481816/jetpack-navigation-handling-deeplinks-manually-in-onnewintent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!