Repository navigation
Make getInitialURL() answer the link that relaunches a reclaimed Android app - #59053
Open
YevheniiKotyrlo wants to merge 1 commit into
Open
YevheniiKotyrlo wants to merge 1 commit into
YevheniiKotyrlo wants to merge 1 commit into
Conversation
…oid app When Android ends a backgrounded app's process but keeps its task, a link relaunches the app into that task: Android recreates the activity from the task's first intent and hands the link to onNewIntent before React Native can emit it as a url event. getIntent() kept answering the task's first intent, so Linking.getInitialURL() returned the first link and the new one never reached JavaScript. ReactActivity.onNewIntent now calls setIntent(intent) first, so getIntent(), and getInitialURL() through it, answer the newest link.
Contributor
Author
YevheniiKotyrlo
marked this pull request as ready for review
October 14, 2026 06:50
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary:
When Android ends a backgrounded app's process but keeps its task, a link to the app relaunches it into that task: Android recreates the activity from the task's first intent and hands the link to
onNewIntent. That happens before the React context exists, soReactHostImpl.onNewIntentdrops the intent ("Tried to access onNewIntent while context is not ready") and nourlevent fires.IntentModule.getInitialURL()then readscurrentActivity.intent, which still holds the task's first link.ReactActivity.onNewIntentnow callssetIntent(intent)first, asActivity.onNewIntentdescribes for an activity whosegetIntent()should return the new intent, soLinking.getInitialURL()answers the link that relaunched the app. A running app still receives the link as aurlevent; a latergetInitialURL()call answers that link rather than the launch link.Fixes #59006
Changelog:
[ANDROID] [FIXED] -
Linking.getInitialURL()returns the link that relaunched an app whose process Android ended, instead of the task's first linkTest Plan:
./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests "com.facebook.react.ReactActivityTest" -Preact.internal.useHermesStable=true: three new tests. Without the change two fail — the activity's intent staysrntester://firstafteronNewIntentdeliversrntester://second, andgetInitialURL()resolves the first link. The third, a launch with no later link, passes either way../gradlew :packages:react-native:ReactAndroid:testDebugUnitTest :packages:react-native:ReactAndroid:compileReleaseKotlin :packages:react-native:ReactAndroid:compileReleaseJavaWithJavac -PenableWarningsAsErrors=true -Preact.internal.useHermesStable=true: 724 tests in 104 suites, 0 failures, and the release sources compile.node ./scripts/format-java.js --checkandnode ./scripts/format-kotlin.js --checkpass.rntester://example/ButtonExample, background the app untilam killends its process with the task still in Recents, then openrntester://example/SwitchExample. Without the change RNTester comes back on the Button page; with it, on the Switch page. Both runs log "Tried to access onNewIntent while context is not ready", sogetInitialURL()is what carries the link.-PenableWarningsAsErrors=true; the rest ofbuild_androidwas not run.