Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native deeplinking and android:launchMode problem

I have been trying deeplinking in a react-native application and trying to directly open a screen inside a navigator. I use react-native-deep-linking and react-navigation as libraries. Also nested navigators are used. Deeplinking works correctly except I have some problems with the android:launchMode property.

This is the results I get for each of the android:launchMode options.

  • android:launchMode="standard" - App opens using the deeplink but opens up an entirely new application.
  • android:launchMode="singleTask" - App opens using the deeplink. If I open the app using another link. App comes to the foreground but it directs to the previous link.
  • android:launchMode="singleTop" - App opens using the deeplink but opens up an entirely new application.
  • android:launchMode="singleInstance" - App opens using the deeplink but opens up an entirely new application.

If I remove the android:launchMode property, again the same thing happens as the "standard" mode because it is the default.

What option can I use to resolve this problem? Is there any @override that I can do inside the main activity?

Below is my AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
        android:name=".MainApplication"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:allowBackup="false"
        android:theme="@style/AppTheme">
    <activity
            android:name=".MainActivity"
            android:launchMode="singleTask"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <category android:name="android.intent.category.VIEW"/>

            <data android:scheme="https" android:host="*.myapplive.com" android:pathPrefix="/"/>
            <data android:scheme="https" android:host="*.myapp.com" android:pathPrefix="/"/>
        </intent-filter>
    </activity>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
</application>

like image 645
buddhiv Avatar asked May 19 '26 02:05

buddhiv


1 Answers

Not sure if still relevant but may help someone in future.

The reason is that when activity is in any mode other than standard, re-opening the app from the background will not replace the original intent used to launch the app from the killed state. Instead, those new intents will be directed to the onNewIntent(Intent intent) method. There, you can call setIntent(Intent intent) in order to replace activity's intent with the new one.

You can override this method in your MainActivity. (Note that when overriding this method in React I had to make it public and not protected as I would usually do in Android. Not sure why yet)

Read more here - https://developer.android.com/reference/android/app/Activity#onNewIntent(android.content.Intent)

like image 184
Vitaly Sokolov Avatar answered May 20 '26 17:05

Vitaly Sokolov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!