Android: Timers do not run if specified before App mounts
See original GitHub issue- Review the documentation: https://facebook.github.io/react-native
- Search for existing issues: https://github.com/facebook/react-native/issues
- Use the latest React Native release: https://github.com/facebook/react-native/releases
Environment
React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Memory: 40.69 MB / 16.00 GB
Shell: 4.4.23 - /usr/local/bin/bash
Binaries:
Node: 10.12.0 - /var/folders/7r/_djt8b5s0tn_c2dmpdcwhjn40000gn/T/yarn--1541193013040-0.8521692356694159/node
Yarn: 1.12.1 - /var/folders/7r/_djt8b5s0tn_c2dmpdcwhjn40000gn/T/yarn--1541193013040-0.8521692356694159/yarn
npm: 6.4.1 - ~/.nvs/node/10.12.0/x64/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
Android SDK:
Build Tools: 23.0.1, 25.0.3, 26.0.2, 26.0.3, 27.0.3, 28.0.1
API Levels: 23, 24, 25, 26, 27, 28
IDEs:
Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
npmPackages:
react: ^16.6.0 => 16.6.0
react-native: ^0.57.3 => 0.57.4
Description
If you call setTimeout
or setInterval
as the very first thing in the application, before any calls to react-native itself, they will never run. They do in iOS.
Reproducible Demo
Wrap your startup AppRegistry call in a setTimeout:
setTimeout(() => AppRegistry.registerComponent(appName, () => App), 100);
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
android - timer task not executing when app is in background
Its possible that your current device is not powerful enough to run the timer. Try restarting the device and stop any applications that...
Read more >DevicePolicyManager - Android Developers
Returns true if the caller is running on a device where the admin can grant ... but the timer won't be reset, so...
Read more >Script Commands for Android Plus Devices - SOTI
Specifies if an application should adhere to the battery optimization restrictions. Note: Supported on Samsung Android devices with Samsung MDM 5.7 or later ......
Read more >Tasker: Event A-Z
The Android alarm clock with the specified label is about to go off. Stop will prevent the system ... Some ROMs do not...
Read more >Working with App State and Event Listeners in React Native
The timer starts after the component's initial render. Also upon the initial render, the AppState change event listener is initialised. · When ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
All of that is entirely in place already… our app is used frequently in retail stores to finance sales, so we wanted to short-circuit the loading timeout if there was no network whatsoever to save customers’ time (potentially standing in line / with a retail rep). I wound up just mounting a headless component that does the check in
componentDidMount()
. It’s probably a frame or two slower, but imperceptibly, so we’ll be shipping the check in the next release. I just figured that since I had noticed the bug in the first place, might as well report it. People might wind up here from google and see that it’s (un)fixed and know whether to start considering a workaround (which, admittedly, would have saved me an hour).Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.