Couldn't call show() without a valid Activity
See original GitHub issueBug report
Summary
Occasionally (but rarely) I get this error due to react-native-bootsplash
, causing the app to hang:
Error: Couldn't call show() without a valid Activity
at anonymous(.../node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:103:promiseMethodWrapper)
at o(.../node_modules/react-native-bootsplash/dist/commonjs/index.js:23:hide)
I am pretty sure that I have react-native-bootslpash
configured as per instructions, as most of the times its works for me as intended (and when the problem happens, killing & restarting the app usually helps to get it loaded).
I suspect you might have some race condition in the code, leading to crash when in some rare cases the RN code is executed and RNBootslash .hide()
is called before the bootslash is correctly loaded.
Environment info
react-native info
output:
System:
OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa)
CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
Memory: 973.41 MB / 11.60 GB
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 14.15.1 - ~/.nvm/versions/node/v14.15.1/bin/node
Yarn: Not Found
npm: 6.14.8 - ~/.nvm/versions/node/v14.15.1/bin/npm
Watchman: Not Found
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Languages:
Java: 11.0.9.1 - /usr/bin/javac
Python: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: ^17.0.1 => 17.0.1
react-native: ^0.63.3 => 0.63.3
npmGlobalPackages:
*react-native*: Not Found
Library version: 3.1.1
Steps to reproduce
I don’t have a realiable way to reproduce. The bug manifests itself randomly from time to time.
In the nutshell I don’t do anything fancy: I have the bootslash installed as per instructions, when my React Native app starts it rapidly does some async initializations, and once they are ready it calls RNBootSplash.hide(..)
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:20 (7 by maintainers)
Top GitHub Comments
@zoontek not quite, now when the issue happens, there is no error, but the splashscreen does not hide either, the
.hide()
call is just silently ignored.In the meantime I found a way to reproduce it: if I deploy the app to device with short screen lock time, and by the moment the deployment is finished the screen is already locked, when I unlock the screen - the app is already open, and this problem is there. Also found a workaround: if instead calling
.hide()
when the app seems ready I just schedule the call 1 second after the root component rendering, it seems to work fine.Probably you need to add some sort of async barrier: so that when
.hide()
is called it actually waits for a flag saying that the splash screen have been shown up already?Hello everyone. I experience the same issue. When the screen is locked and the build (no matter if debug or release) is finished and I unlock the screen I see bootsplash. Then when I kill the app and open it again everything works as expected. It’s only happening after installation. To be precise it’s also happening for anyone who will download the app from Google Play “Internal testing”.
I did what @birdofpreyru said which is adding setTimeout in root component (App.js) render to execute
.hide()
after one second and now it works.I’m sorry but I’m new to programming therefore if my help is required to somehow reproduce the issue or anything - you’ll need to be the most direct as possible 😃