Android deep links opens in the app I linked from instead of launching a separate instance of my app
Asked Answered
W

1

12

I am using react-native. Deep linking is working great for ios. For Android however, I can't seem to figure out how to open my app properly from deep links.

When opening a deep link from e.g. Firefox, my app is launched inside the firefox window. It is the same when I use a deep link-tester app. Everything works as intended with the app with the exception that it is not launched from the proper app.

What am I doing wrong? Here is an excerpt from my AndroidManifest.xml:

    <activity 
         android:name=".MainActivity"
         android:label="@string/app_name"
         android:configChanges=
             "keyboard|keyboardHidden|orientation|screenSize" 
         android:windowSoftInputMode="adjustResize"  
         android:exported="true">
      <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="myapp" />
      </intent-filter>
    </activity>
Wapiti answered 2/9, 2019 at 7:14 Comment(0)
C
27

Take a look at https://developer.android.com/guide/components/activities/tasks-and-back-stack

When declaring an activity in your manifest file, you can specify how the activity should associate with a task using the element's launchMode attribute.

The launchMode attribute specifies an instruction on how the activity should be launched into a task. There are four different launch modes you can assign to the launchMode attribute:

Try putting android:launchMode="singleTask" on your activity tag

The system creates a new task and instantiates the activity at the root of the new task. However, if an instance of the activity already exists in a separate task, the system routes the intent to the existing instance through a call to its onNewIntent() method, rather than creating a new instance. Only one instance of the activity can exist at a time.

https://developer.android.com/guide/components/activities/tasks-and-back-stack#ManifestForTasks

Further background reading includes (and many other things you can try):

FLAG_ACTIVITY_NEW_TASK clarification needed

Android Task Affinity Explanation

Cony answered 2/9, 2019 at 7:24 Comment(1)
Oh perfect, thank you very much. I had stumbled upon this before but accidentally put it in my MainApplication-tag and not in my MainActivity... I guess I need to improve my reading skills!Wapiti

© 2022 - 2024 — McMap. All rights reserved.