Repository navigation
Commit ea5882b
Don't resume the new context without an Activity after a reload on Android (#59474)
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
Pull Request resolved: #59474
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.
Reviewed By: christophpurrer
Differential Revision: D127564742
Pulled By: javache
fbshipit-source-id: 37a80ed86e799473bfc6ed251f60c5ae585067721 parent 9c8a368 commit ea5882b
2 files changed
Lines changed: 35 additions & 1 deletion
File tree
- packages/react-native/ReactAndroid/src
- main/java/com/facebook/react/runtime
- test/java/com/facebook/react/runtime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1109 | 1109 | | |
1110 | 1110 | | |
1111 | 1111 | | |
1112 | | - | |
| 1112 | + | |
1113 | 1113 | | |
1114 | 1114 | | |
1115 | 1115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
171 | 205 | | |
0 commit comments