Home > Software design >  How to keep the application running in background react native
How to keep the application running in background react native

Time:08-25

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

CodePudding user response:

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.

CodePudding user response:

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

  • Related