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.

Can't simulate background fetch event multiple times - just once

See original GitHub issue

Your Environment

  • Plugin version: 2.4.3
  • Platform: Android
  • OS version: 7, 8
  • React Native version (react-native -v): 0.52.1
  • Plugin config Inside App.js
async componentDidMount() {
    BackgroundFetch.configure({
      enableHeadless: true,
      minimumFetchInterval: 15, // <-- minutes (15 is minimum allowed)
      stopOnTerminate: false,   // <-- Android-only,
      startOnBoot: true         // <-- Android-only
    }, async () => {console.log("BF: APP.JS");
      await someAsyncFunction();
      BackgroundFetch.finish(BackgroundFetch.FETCH_RESULT_NEW_DATA);
    }, (error) => {
      console.log("RNBackgroundFetch failed to start");
    });

Expected Behavior

To simulate background fetch event on device with command: adb shell cmd jobscheduler run -f com.scoutsssag.app 999 multiple times

Actual Behavior

I run adb shell cmd jobscheduler run -f com.scoutsssag.app 999 once and after 1min I try again nothing happens. Is this normal or should be possible?

This is log when I simulate first time:

$ adb logcat *:S ReactNative:V ReactNativeJS:V TSBackgroundFetch:V
--------- beginning of crash
--------- beginning of system
--------- beginning of main
09-19 11:10:04.493 27409 27409 D TSBackgroundFetch: - onStopJob
09-19 11:12:13.821 27409 27409 D TSBackgroundFetch: - Background Fetch event received

When I execute same command again nothing in logs.

In this logs you can see at 11:34:43 I get onStopJob and then I was able to execute simulate command again but I got only received log my code is not executed.

--------- beginning of main
09-19 11:10:04.493 27409 27409 D TSBackgroundFetch: - onStopJob
09-19 11:12:13.821 27409 27409 D TSBackgroundFetch: - Background Fetch event received
09-19 11:22:13.840 27409 27409 D TSBackgroundFetch: - onStopJob
09-19 11:24:43.088 27409 27409 D TSBackgroundFetch: - Background Fetch event received
09-19 11:34:43.118 27409 27409 D TSBackgroundFetch: - onStopJob
09-19 11:35:14.352 27409 27409 D TSBackgroundFetch: - Background Fetch event received

Here are logs I left the phone still not touching app. You can see that in a first background fetch it entered function and executed code “TOTAL: 30” but see logs after it, I don’t understand what could be cause of this:

09-19 11:53:28.116  5471  5471 D TSBackgroundFetch: - Background Fetch event received
09-19 11:53:28.128  5471  5560 I ReactNativeJS: ENTERED APP.JS
09-19 11:53:28.132  5471  5560 I ReactNativeJS: INSIDE FUNCTION IN APP.JS
09-19 11:53:32.991  5471  5560 I ReactNativeJS: 'TOTAL: ', 30
09-19 12:03:28.125  5471  5471 D TSBackgroundFetch: - onStopJob
09-19 12:03:58.244  5471  5471 D TSBackgroundFetch: - Background Fetch event received
09-19 12:03:58.248  5471  5560 I ReactNativeJS: BF: APP.JS
09-19 12:03:58.249  5471  5560 I ReactNativeJS: INSIDE FUNCTION
09-19 12:13:58.252  5471  5471 D TSBackgroundFetch: - onStopJob
09-19 12:14:58.361  5471  5471 D TSBackgroundFetch: - Background Fetch event received
09-19 12:14:58.365  5471  5560 I ReactNativeJS: BF: APP.JS
09-19 12:14:58.365  5471  5560 I ReactNativeJS: INSIDE FUNCTION
09-19 12:24:58.368  5471  5471 D TSBackgroundFetch: - onStopJob
09-19 12:28:11.661  5471  5471 D TSBackgroundFetch: - Background Fetch event received
09-19 12:28:11.694  5471  5560 I ReactNativeJS: BF: APP.JS
09-19 12:28:11.695  5471  5560 I ReactNativeJS: INSIDE FUNCTION
09-19 12:38:11.700  5471  5471 D TSBackgroundFetch: - onStopJob
09-19 12:42:01.618  5471  5560 I ReactNativeJS: remote-redux-devtools: Socket connection errors are being suppressed. 
09-19 12:42:01.618  5471  5560 I ReactNativeJS: This can be disabled by setting suppressConnectErrors to 'false'.
09-19 12:42:01.620  5471  5560 I ReactNativeJS: [SocketProtocolError: Socket closed without status code]
09-19 12:43:11.702  5471  5471 D TSBackgroundFetch: - Background Fetch event received
09-19 12:43:11.704  5471  5560 I ReactNativeJS: BF: APP.JS
09-19 12:43:11.705  5471  5560 I ReactNativeJS: INSIDE FUNCTION
09-19 12:53:11.711  5471  5471 D TSBackgroundFetch: - onStopJob
09-19 13:02:45.730  5471  5471 D TSBackgroundFetch: - Background Fetch event received
09-19 13:02:45.741  5471  5560 I ReactNativeJS: BF: APP.JS
09-19 13:02:45.741  5471  5560 I ReactNativeJS: INSIDE FUNCTION
09-19 13:12:45.745  5471  5471 D TSBackgroundFetch: - onStopJob

I noticed that I can simulate call again when I receive onStopJob in log. But again then it doesn’t complete function like first time.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
christocracycommented, May 2, 2019

News on what? This issue is closed.

0reactions
christocracycommented, May 2, 2019

I have no idea.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I can not simulate the background fetch on the device in xcode
when I simulate the background fetch in the simulator it works. ... the debugger just causes confusion and leads to a lot of...
Read more >
ios 8 Background fetch is never called on device more than ...
I created a test app for background fetches on iOS. And it works fine on the simulator via Debug -> Simulate Background fetch....
Read more >
@transistorsoft/capacitor-background-fetch - npm
Background Fetch is a very simple plugin which attempts to awaken an app in the background about every 15 minutes, providing a short...
Read more >
Modern Backgrounds Tasks in iOS 13 - Andy Ibanez
When you schedule a task, it will only be executed once. If you want to keep executing it throughout the day, you simply...
Read more >
background_fetch | Flutter Package - Pub.dev
Background Fetch is a very simple plugin which will awaken an app in the background about every 15 minutes, providing a short period...
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