Deeplink isn't correctly redirect if the app is already opened

自作多情 提交于 2020-05-17 06:12:05

问题


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.

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.

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


回答1:


As per the handleDeepLink() documentation:

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 doesn't override methods in your activity, so you'd need to call this manually if you insist on using android:launchMode="singleTask".

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.



来源:https://stackoverflow.com/questions/61480730/deeplink-isnt-correctly-redirect-if-the-app-is-already-opened

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