react-native-background-fetch: Unable to make a fetch when app is running in background
I have configured a background task in android and i want it to be triggered every 15mins irrespective of the app state. im using both configure and registerHeadlessTask
BackgroundFetch.configure({
minimumFetchInterval: 15, // <-- minutes (15 is minimum allowed)
stopOnTerminate: false, // <-- Android-only,
enableHeadless: true // <-- Android-only
},task, (error) => {
console.log("[js] RNBackgroundFetch failed to start ::::", err);
});
BackgroundFetch.registerHeadlessTask(task);
Your Environment
- Plugin version: 2.5.6
- Platform: Android
- React Native version (
react-native -v
): 0.57.7
Expected Behavior
background task should work when the app is running in background or even when it is killed
Actual Behavior
the background task is working when the app is not running, but when the app is in running in the background, the task is triggered but then fetch is not happening and I get the response when I open the app
Context
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 16 (6 by maintainers)
Hi @christocracy, we do have the same problem like @gghnisan. The headlessjs task does not run if the app is killed.
Some logs:
Here is a repo with simple repro app. https://github.com/skaldo/BackgroundFetchBug
Device is Samsung Galaxy S8 running Android 9.
Could you please check if there’s something wrong with the code? Just run it with
react-native run-android --variant=release
, signing is configured. Thanks!