react-native-background-fetch: Background fetch not working if app is closed

Your Environment

  • Plugin version: ^4.1.8
  • Platform: Android
  • OS version: 11
  • Device manufacturer / model: Oppo
  • React Native version (react-native -v): 0.70.6
  • Plugin config

The Background fetch works if the app is not killed but it stops once the app is terminated

Expected Behavior

I expect the myFunction function to run even if the app is closed

Actual Behavior

The function does not run

Steps to Reproduce

Here is my code

  const myFunction = () => {
    return new Promise((resolve, reject) => {
      const date = Date.now();
      console.log('- myFunction ' + date);
      resolve({success: true});
    });
  };

  BackgroundFetch.configure(
    {
      minimumFetchInterval: 15,
      enableHeadless: true,
      forceAlarmManager: true,
      stopOnTerminate: false,
      startOnBoot: true,
      periodic: true,
      requiresCharging: false, // Default
      requiresDeviceIdle: false, // Default
      requiresBatteryNotLow: false, // Default
      requiresStorageNotLow: false, // Default
    },
    async taskId => {
      const result = await myFunction();
      console.log('- result: ', result);
      BackgroundFetch.finish(taskId);
    },
    taskId => {
      console.log(`Task ${taskId} timed out`);
      BackgroundFetch.finish(taskId);
    },
  );

Debug logs

Screenshot 2023-02-27 035030

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 20 (9 by maintainers)

Most upvoted comments

follow the api docs and actually read them.