Android deeplink with navigation component not working as expected
Asked Answered
M

1

17

I hope you are all doing well.

I have a little question;

I am using navigation component, single activity multiple fragment. I have a tiny problem with deeplink.

  • I’ve set <nav-graph/> in manifest and also set launcherMode="singleTask",

  • I’ve set <deeplink/> in navigation graph.

  • I’ve handled intent extras in fragment.

My flow is;

  1. User clicks to forgot password, fills edit texts then requests deeplink mail. Works fine
  2. User clicks to deeplink in email and selects app then navigates to CreatePasswordFragment automatically (deeplink destination fragment) & (I can handle args here, works fine also)

The problem is; Sometimes if app is open on background, (for example I requested mail then pressed home button) and when I click deeplink, last fragment runs instead of destination fragment which is CreatePasswordFragment Any ideas about what may cause the problem?

Thanks!

Navigation version: 2.2.0

Deeplink that comes with email

 http://myurl/forgot-password/?key=sodmoq9wwdW1djkssdqMEdqlsp

Navigation graph

 <deepLink android:id="@+id/deepLink"
    app:uri="http://myurl/forgot-password/?key={key}"/>
 <argument
    android:name="key"
    app:argType="string" />

Android Manifest

 <activity 
    ...
    android:launchMode="singleTask">
 <nav-graph android:value="@navigation/navigation_main" />
 </activity>`

Decompiled Manifest

 <intent-filter>

     <action android:name="android.intent.action.VIEW" />

     <category android:name="android.intent.category.DEFAULT" />

     <category android:name="android.intent.category.BROWSABLE"/>

     <data android:scheme="http" />

     <data android:host="myurl" />

     <data android:path="/forgot-password/" />
 </intent-filter>
Mutate answered 14/2, 2020 at 9:19 Comment(5)
Have you managed to solve that problem?Residency
@Residency unfortunately no.Pentameter
I tried to manually handle deep link by catching intent and then explicitly navigating to requested fragment by calling findNavController().navigate(), but after that I'm unable to navigate from this new fragment to another fragment neither by pressing back key nor by calling navigate() method. Do you use some workaround for this?Residency
@MithatSinanSarı any luck with it?Wilderness
@Wilderness unfortunately, no. We handle manually right now.Pentameter
A
2

Little late to the party, but for future references quoting from Ian Lake's (tech lead of the navigation component) answer:

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

And here is the link to the source:

https://mcmap.net/q/746969/-deeplink-isn-39-t-correctly-redirect-if-the-app-is-already-opened

Aggappora answered 16/11, 2020 at 3:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.