Skip to content

Don't resume the new context without an Activity after a reload on Android - #59474

Closed
lazerg wants to merge 1 commit into
react:mainfrom
lazerg:fix/issue-59473-reload-null-activity
Closed

lazerg wants to merge 1 commit into
react:mainfrom
lazerg:fix/issue-59473-reload-null-activity

Conversation

@lazerg

@lazerg lazerg commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Summary:

If the Activity is destroyed while a reload is still running, ReactHostImpl finishes the reload by calling moveToOnHostResume(reactContext, currentActivity) with currentActivity already null. The new context gets onHostResume(null) and the lifecycle state becomes RESUMED, so when the app is reopened onHostResume(activity) returns early and getCurrentActivity() stays null until the next pause/resume. That's what makes PermissionsAndroid.request() reject with E_INVALID_ACTIVITY (and likely the Alert error in #46201).

The reload branch now only resumes the context when there is an Activity. Otherwise it falls through to the normal path, and the next onHostResume(activity) resumes the context with the right Activity.

Fixes #59473

Changelog:

[ANDROID] [FIXED] - Fix getCurrentActivity() staying null after the Activity is destroyed during a reload

Test Plan:

Added ReactHostTest.testActivityDestroyedDuringReload. It queues background work so the Activity can be paused and destroyed before the reload finishes, then resumes a new Activity and checks the new context gets it. On main it fails (state is RESUMED and the context only got onHostResume(null)), and it passes with this change. ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest passes and ktfmt is clean. I didn't run the reproducer on a device.

@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 26, 2026
@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 26, 2026
@github-actions

Copy link
Copy Markdown

Visual regression

No visual differences at 314dcea3c46d.

ios: no capture

@meta-codesync

meta-codesync Bot commented Oct 26, 2026

Copy link
Copy Markdown

@javache has imported this pull request. If you are a Meta employee, you can view this in D127564742.

@meta-codesync meta-codesync Bot closed this in ea5882b Oct 26, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Oct 26, 2026
@meta-codesync

meta-codesync Bot commented Oct 26, 2026

Copy link
Copy Markdown

@javache merged this pull request in ea5882b.

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. Merged This PR has been merged. 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.

[Android][Bridgeless] Destroying the Activity during a JS reload leaves ReactContext.getCurrentActivity() null until the app is backgrounded

1 participant