I have deep links set up on a React-Native app. iOS works fine.
On Android, if the app is already in the background the deep link works.
However, if the app is booting up fresh, the deep link opens the app but doesn’t trigger the redirect.
As far as I can see, the link is available in the MainActivity
onCreate()
function via the intent.
When the app opens I am processing the link but in this case, Linking.getInitialURL()
produces a null
value.
The caveat here is that I have a SplashActivity which is set as the android.intent.category.LAUNCHER
.
This passes back to the MainActivity (and as I say, the deep link is there in extras).
I’ve tried making MainActivity the LAUNCHER and but this results in multiple instances of the app opening when a deep link is triggered vs opening the app via the home screen.
Both MainActivity and SplashActivity are set to android:launchMode="singleTask"
Can anyone offer any insight into the correct way of setting this up on Android.
2
Answers
This was a little complicated but I think I have a working solution now.
SplashActivity
is set as this in my manifest:The SplashActivity does the following (where
url
is the deeplink):...then in MainActivity I have the following to catch the deep link on a fresh app open:
as well as
...so that
Linking.getInitialURL()
over on the react-native side now picks up the deep link if the app was in the background or if it's opening from closed state.This also prevents the 'multiple instance' problem so there is only ever 1 open.
Would you try this in your AndroidManifest.xml
and in you app.js file