-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Android) getCurrentActivity() sometimes returns null inside ReactContextBaseJavaModule.getConstants() #37518
Comments
|
This issue 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. |
Still requires attention. Please help out 🙏🏻 |
Ping |
It's also valid for 2024. |
## Summary Should fix: #5892. We do not check if the current activity is `null` and it seems that it randomly can be null. It seems like ongoing issue on react native side: facebook/react-native#37518, facebook/react-native#18345. The `useAnimatedKeyboard` hook won't work when the app when current activity is `null`, but it should not crash the app anymore. Our assumption is that most of the libs handle it this way (#5892), so it must be some corner case when most functionality won't work - that's why we don't try to recover from this state. --------- Co-authored-by: Krzysztof Piaskowy <krzysztof.piaskowy@swmansion.com>
Ping. we'd love to see this fixed for Maestro use |
This issue 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. |
ping |
Is this still an issue on 0.76? |
Warning Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:
|
I suspect I do have this very occasionally under unknown circumstances. Not helpful, but pinging the world it does happen. |
This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days. |
This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days. |
up |
This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days. |
up |
Description
ReactContextBaseJavaModule
has a method calledgetCurrentActivity()
. When used insideReactContextBaseJavaModule.getConstants()
(actually,BaseJavaModule.getConstants()
) - namely, during app launch (Javascript init), it sometimes returns the current activity, and sometimesnull
in what seems to be a random behavior.React Native Version
0.70.7
Output of
npx react-native info
Steps to reproduce
react-native init
NativeModule
that looks roughly like so:ReactNativeHost.getPackages()
method.index.js
(orapp.js
), add the following import at the top:react-native run-android
), and follow the logs usinglogcat
. You will end up seeing something like this, in consequent runs:(and so on and so forth)
Snack, code example, screenshot, or link to a repository
For starters, this report is in fact the reason behind this bug, which has been reported by me to the
react-native-launch-arguments
repo.As for the problem itself - it is rooted in the handling of
mCurrentActivity
, here:While
mCurrentActivity
is set inonHostResume()
, which is a bit late compared to when the activity gets initially created,getConstants()
can be called by RN's initialization sequence in very early stages. Add to that the fact the two occur in an asynchronous way (i.e. in different, async threads) - you get that the call togetCurrentActivity()
is very likely to miss the completion of the initialization ofReactContext.mCurrentActivity
. These circumstances induce the mentioned behavior, which is highly nondeterministic and "feels random".Solutions
There are quite a few nonoverlapping alternatives to how this can be resolved:
The text was updated successfully, but these errors were encountered: