fix(android): onHostPause
crashes with multiple active activities
#54122
+12
−14
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:
This PR addresses the problem outlined here:
Problems tl;dr:
ReactHost
doesn'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 theReactHost
while the app is still in foreground (thats my assumption, maybe I am wrong here):ReactHost
is held by theMainApplication
(in the past it was theReactActivity
). It wants to be notified when the whole app gets paused to:react-native/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt
Lines 258 to 281 in e926ad0
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 theReactInstance
was 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