Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android deeplink with navigation component not working as expected

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>
like image 714
Mithat Sinan Sarı Avatar asked Feb 14 '20 09:02

Mithat Sinan Sarı


People also ask

What is the difference between deep linking and deferred deep linking?

In the context of mobile apps, deep linking consists of using a uniform resource identifier (URI) that links to a specific location within a mobile app rather than simply launching the app. Deferred deep linking allows users to deep link to content even if the app is not already installed.

What is deep link in navigation component?

In Android, a deep link is a link that takes you directly to a specific destination within an app. The Navigation component lets you create two different types of deep links: explicit and implicit.

How do I configure Deeplinks?

Adjust Deeplink Generator To use the tool, log in to your Adjust dashboard and open the Menu, where you'll see the 'Deeplink Generator' as an option. Click to open, and you'll find a page to input the information required to create your deep link. Then simply copy and paste into whichever campaign you've set up.

What is a deep link in Android?

In Android, a deep link is a link that takes you directly to a specific destination within an app. The Navigation component lets you create two different types of deep links: explicit and implicit. An explicit deep link is a single instance of a deep link that uses a PendingIntent to take users to a specific location within your app.

What are deep links in the navigation component?

The Navigation component lets you create two different types of deep links: explicit and implicit. An explicit deep link is a single instance of a deep link that uses a PendingIntent to take users to a specific location within your app. You might surface an explicit deep link as part of a notification or an app widget, for example.

How do I create a deep link in Android navcontroller?

val componentName = ... If you have an existing NavController , you can also create a deep link by using NavController.createDeepLink (). An implicit deep link refers to a specific destination in an app. When the deep link is invoked—for example, when a user clicks a link—Android can then open your app to the corresponding destination.

What type of deep link does the “continue editing” action use?

The “continue editing” action uses an “explicit” deep link. Explicit is what we call a link that takes you to dynamic content inside your application. Let’s start with an implicit deep link to add a new donut.


1 Answers

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://stackoverflow.com/a/61569940/4408458

like image 156
Jason Avatar answered Oct 21 '22 02:10

Jason