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

1

8

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?

Cardioid answered 28/4, 2020 at 12:57 Comment(3)
It seems normal. When activity already created just its onNewIntent method called for this process. You should put your logic inside the onNewIntent method.Interdict
This is the intended behavior of single task launch mode.Ulloa
But why Jetpack Navigation is not handling it by default?Cardioid
B
10

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.

Buckeen answered 3/5, 2020 at 5:17 Comment(1)
Thanks Ian, I'm using Branch SDK and singleTask is required by this 3rd party. My pattern to handle deeplinks I posted here #61482316 it's not the most beautiful, but seems to work. CheersCardioid

© 2022 - 2024 — McMap. All rights reserved.