如果已打开应用,则Deeplink无法正确重定向 [英] Deeplink isn't correctly redirect if the app is already opened

查看:449
本文介绍了如果已打开应用,则Deeplink无法正确重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jetpack导航进行深层链接。我已将 android:launchMode = singleTask 添加到我的活动中。如果之前未打开
Deeplink,则会正确重定向该应用。但是,如果该应用程序存在于内存中,则该应用程序将进入前台,但无法正确打开Deeplink。

I'm using Jetpack Navigation for deeplinks. I've added android:launchMode="singleTask" to my Activity. Deeplink is redirected correctly if the app wasn't opened before. However, if the app exists in memory, the app is coming to the foreground but deeplink isn't opened correctly.

我的设备是搭载Android 10的Pixel2。
我看到 onCreate 仅在我第一次打开应用程序时被调用。但是,每次单击深度链接时,都会调用 onNewIntent

My device is Pixel 2 with Android 10. I see that onCreate is called only the first time I'm opening app. However, onNewIntent is called every time I'm clicking deeplink.

这是Jetpack Navigation中的错误还是我设置时忘记了什么?

Is it a bug in Jetpack Navigation or I forgot about something when setting it up?

推荐答案

按照 handleDeepLink()文档


如果在构造时传入了 Activity 作为上下文,则在您第一次设置图形时会自动为您调用此NavController,,但如果您的活动在 Activity.onNewIntent(Intent) 中收到新的Intent,则应手动调用。

This is called automatically for you the first time you set the graph if you've passed in an Activity as the context when constructing this NavController, but should be manually called if your Activity receives new Intents in Activity.onNewIntent(Intent).

NavController 不会覆盖活动中的方法,因此如果您坚持要手动调用此方法关于使用 android:launchMode = singleTask

NavController doesn't override methods in your activity, so you'd need to call this manually if you insist on using android:launchMode="singleTask".

根据单人活动会话,您根本不应使用任何 launchMode 标志- defau实际上是99.9%的时间您想要的。

As per the Single Activity talk, you shouldn't use any launchMode flags at all - the default is actually what you want 99.9% of the time.

这篇关于如果已打开应用,则Deeplink无法正确重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆