-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Deep link via intent creates multiple instances of MainActivity #7079
Comments
Additional info from android
and
|
Hey, That's correct and expected (in a sense that As you can see from the links provided (https://github.com/facebook/react-native/blob/master/Libraries/Linking/Linking.js#L120):
If you could submit a PR with that functionality it would be cool! (unless someone's already working on that at Facebook internally, cc: @mkonicek). The emitter is there, but the underlying code to We might consider changing the type to PS. I could help since I am using the similar setup, however I am using Branch.io behind the scenes and that's the place I've added the |
Makes sense. Yeah. The shortest path from onNewEvent of MainActivity to RCTDeviceEventEmitter will require some care, but it seems like a necessary connection that wouldn't hurt anything to exist. Agreed on leaving config to users and avoiding modifying the generator, if possible. Remaining question is just whether there's other consequences of the behavior. (Effect on existing non-root activities?) My understanding is that most android apps consist of many activities so that this is a little smoother, but that RN heavily manages a single activity so that singleInstance is a better fit if using intents. |
@grabbou — It's a shot in the dark, but I cleaned up our solution and submitted a PR. 🎉 At best it needs a couple tweaks, and at worst it's not a proper fit for this feature. More than a little skeptical that it was so simple. Which leads me to believe maybe it's not implemented for a reason. Feedback welcome though! |
I am using RN 23, and R 14.8. |
@skyride99 how are you building RN for android? I was rather surprised to learn (compared to iOS) that android RN libraries are distributed as a binary so that modifying the source in Glad to offer further thoughts, but that's the first thing that comes to mind. I got pretty frustrated before realizing the changes never had any effect! |
Thats the issue. It has to be rebuilt. Thanks for the tip. I appreciate the work. I hope the RN team will put in the next release. |
@skyride99 It's also possible to do this strictly within the confines of your app. It requires adding |
Summary: Fixed facebook#7118 by rreusser Closes facebook#7940 Differential Revision: D3391586 fbshipit-source-id: f7e572a91347fb0629602374cb6944eabf5b0e8f
Summary: Fixed facebook#7118 by rreusser Closes facebook#7940 Differential Revision: D3391586 fbshipit-source-id: f7e572a91347fb0629602374cb6944eabf5b0e8f
Hi there! This issue is being closed because it has been inactive for a while. But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/android-deep-link-via-intent-creates-multiple-instances-of-mainactivity Product Pains has been very useful in highlighting the top bugs and feature requests: Also, if this issue is a bug, please consider sending a pull request with a fix. |
I see it looks like the issue was since fixed in PR #7940 but I am having the same problem on RN 0.51.0. I have added |
Nevermind, I see you must use the listeners to handle the new url. Makes sense that getInitialURL wouldn't have been the answer.
|
We've configured
<intent-filter>
for our Android app as described in the docs so that our app can use oauth and handle deep links.Expected behavior: intent can be received and handled by existing instance of
MainActivity
.Observed behavior: the default configuration (
android:launchMode="standard"
) ofMainActivity
causes every received intent to create an entirely new instance ofMainActivity
—which is received correctly bygetInitialURL
except now we have multipleMainActivity
instances.Version: 0.23.1, but nothing in 0.24 release notes suggests the behavior has changed.
See below for illustration. Here is the full example: https://github.com/rreusser/react-native-android-intent-issue
A solution: Adding
android:launchMode="singleTask"
to theMainActivity
definition prevents multiple instances by routing the intent to the existing activity, but thengetInitialURL
is not adequate to handle deep links since it's no longer an initial URL. The solution in turn is foronNewIntent
ofMainActivity
to send an'openURL'
event throughRCTDeviceEventEmitter
, which can be received by a (trivially) completed version ofLinking.addEventListener
for Android—which unless I'm mistaken is just a copy/paste job once the device event emitter is hooked up to onNewIntent.This can be solved in userland, but the default
launchMode
ofMainActivity
leads to odd and problematic behavior that it's hard to imagine is what's usually desired. I'm glad to clean up our solution into a PR, but before going to the trouble wanted to confirm that this indeed a correct understanding of the problem and solution and that a fix isn't either intentionally relegated to userland or already on the way.tl;dr: Unless I'm wrong, this all a long-winded way of describing what I believe would basically complete the implementation of
Linking
for Android.Thanks!
The text was updated successfully, but these errors were encountered: