fix(android): onHostPause crashes with multiple active activities#54122
fix(android): onHostPause crashes with multiple active activities#54122hannojg wants to merge 1 commit into
onHostPause crashes with multiple active activities#54122Conversation
fix(android): crash `onHostPause` with multiple active activities
|
After thoughts Right now this would break the documentation on So I think either we should
|
|
You'll see there's a featureflag in this code Thanks for the PR, @fabriziocucci: does this approach make sense? |
|
Thanks a lot for the PR @hannojg! 🙌 I'm gonna be looking at this (hopefully) next week, will let you know as soon as I've evaluated this and potentially other options. |
Hey @fabriziocucci any updates about this PR? |
|
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
Summary:
This PR addresses the problem outlined here:
Problems tl;dr:
ReactHostdoesn't account for the fact that there can be multiple activities at the same time foregrounded.There are scenarios where we can have multiple activities can be in
resume, and we don't want to pause theReactHostwhile the app is still in foreground (thats my assumption, maybe I am wrong here):ReactHostis held by theMainApplication(in the past it was theReactActivity). It wants to be notified when the whole app gets paused to:https://github.com/facebook/react-native/blob/e926ad04288b7e7ca35f228eae21874a0f9155f6/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt#L258-L281
However, when the app is still in foreground by means of another
ReactActivity, neither do we want to disable the back btn handling, nor notify that the app is full on pause.Hence, the fix is to:
Note
Currently I removed all the checking code in
onHostPause, as i believe its not needed, and potentially inherited from times where theReactInstancewas bound to a specific activity on the old arch.I can ofc add it back, or guard my new approach around a feature flag if thats preferred.
Changelog:
[ANDROID] [FIXED] - Android can crash when multiple activities are in foreground and one pauses (fixes "Pausing an activity that is not the current activity, this is incorrect!")
Test Plan:
I tested these changes on top of the reproduction changes mentioned in the issue, and confirm that the app no longer crashes:
output_fixed.mp4