I have a react native application which is doing some task and sending the data to the backend. I want this task to keep running even if the app is closed, as in the app should keep running on the background of device.
NOTE: this app will only run in android
3
Answers
You can make use of this library https://github.com/transistorsoft/react-native-background-fetch. There’s good documentation about how to set it up & what you have to do in order to ensure that the app will execute tasks even when in background/killed. This is a little bit of a grey area and background tasks are usually not 100% reliable, but this library provides good solution.
It’s always good to use native functionality. If you want to execute JavaScript tasks in background. Then implement it using Headless JS https://reactnative.dev/docs/headless-js-android
I found a Libarry which works well in ANDROID even while Screen is OFF
https://github.com/ocetnik/react-native-background-timer
Follow the Installation and call the Function as Example====>
This Also works in IOS but stopes if you Keep APP in Background for Longer than 2 Minutes i have No idea why
please if some one Know how to have this in IOS … PLEASE Help.
also i tried github.com/Rapsssito/react-native-background-actions Library
This also has same Problem in IOS
and it doesn’t work in ANDROID.. i am using Android 12