question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android: Timers do not run if specified before App mounts

See original GitHub issue

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:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
EdwardDrapkincommented, Nov 7, 2018

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).

0reactions
stale[bot]commented, Aug 9, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found