Skip to content

Make getInitialURL() answer the link that relaunches a reclaimed Android app - #59053

Open
YevheniiKotyrlo wants to merge 1 commit into
react:mainfrom
YevheniiKotyrlo:fix/android-relaunch-link-initial-url
Open

YevheniiKotyrlo wants to merge 1 commit into
react:mainfrom
YevheniiKotyrlo:fix/android-relaunch-link-initial-url

Conversation

@YevheniiKotyrlo

@YevheniiKotyrlo YevheniiKotyrlo commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

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, so ReactHostImpl.onNewIntent drops the intent ("Tried to access onNewIntent while context is not ready") and no url event fires. IntentModule.getInitialURL() then reads currentActivity.intent, which still holds the task's first link.

ReactActivity.onNewIntent now calls setIntent(intent) first, as Activity.onNewIntent describes for an activity whose getIntent() should return the new intent, so Linking.getInitialURL() answers the link that relaunched the app. A running app still receives the link as a url event; a later getInitialURL() 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 link

Test 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 stays rntester://first after onNewIntent delivers rntester://second, and getInitialURL() 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 --check and node ./scripts/format-kotlin.js --check pass.
  • RNTester on an Android 16 emulator, before and after: open rntester://example/ButtonExample, background the app until am kill ends its process with the task still in Recents, then open rntester://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", so getInitialURL() is what carries the link.
  • The debug RNTester builds pass with -PenableWarningsAsErrors=true; the rest of build_android was not run.

…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.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 14, 2026
@YevheniiKotyrlo

Copy link
Copy Markdown
Contributor Author

Device evidence — before / after

UNFIXED — after the process is killed with the task kept in Recents, rntester://example/SwitchExample relaunches RNTester on the Button page, the link that opened the task.

FIXED — the same relaunch opens the Switch page.

before — main at 977ca0a204 after — with this PR

RNTester debug builds from main at 977ca0a204 with and without this change, embedded bundle, on an Android 16 (API 36) emulator, 1140×2400 at density 480. Each run opens rntester://example/ButtonExample, goes Home, opens Settings, goes Home, runs am kill com.facebook.react.uiapp until pidof prints nothing, checks the task is still in dumpsys activity recents, and opens rntester://example/SwitchExample. Both builds log "Tried to access onNewIntent while context is not ready" on the relaunch.

@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as ready for review October 14, 2026 06:50
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 14, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linking.getInitialURL() returns the task's first link after a link relaunches a reclaimed Android app

1 participant