Background Processing for React Native Applications in 2022
A background process does work for a computer in a way that optimizes performance of the user interface. If you are new to background processing, check out this article. There are several options for background processing regarding react native applications, each with their own trade-offs and levels of built-in functionality. The following is a brief overview of each option along with a list of advantages and disadvantages.
This is a fairly simple but well maintained background worker created by a company called Transistor Software which specializes in making native location API’s that run in the background. React native background fetch will perform periodic work once every 15 minutes and works on both Android and iOS.
Advantages
Disadvantages
This module is very similar to react-native-background-fetch in that it offers iOS and Android support for a periodic worker that executes a task no faster than once every 15 minutes. It offers a few different features as compared to react-native-background-fetch but is NOT maintained and has some pretty restrictive limitations.
Advantages
Disadvantages
Recommended by LinkedIn
React Native Background Worker offers the most amount of features as compared with the other options. It has the ability to do periodic work OR manage a queue of tasks among other things. It is built on Android SDK’s own feature-rich WorkManager API. Despite having some of these advantages, it also has some downsides including NOT being well maintained and having at least one feature that no longer works (canceling a task). Still though, this module does have some nice features and if someone were to maintain it and incorporate even just a little more of Android WorkManager’s functionality, this module would be a home run for background processing on Android applications.
Advantages
Disadvantages
Headless JS is react-native’s own approach to executing processes for Android only. It utilizes Android SDK’s Services application component and does require that you write some native code in order to get it up and running. Further, headless JS only offers some basic features such as the ability to specify how headless JS will approach retrying tasks (in case of failure). If you need to manage a queue of tasks or even periodic work on tasks, you’ll have to write this functionality yourself.
Advantages
Disadvantages
Conclusion
There is not ONE module that includes all of the best functionality for both iOS and Android. Instead, we are left with only several options that have some trade-offs. However, I DO believe there is currently a best option for each platform. For android, the best options are react-native-background-worker for being feature-rich and react-native-background-fetch for its simplicity of use and being well maintained. For iOS, again the best option here would be react-native-background-fetch for the same reasons as Android. Ideally in the future though, there is great opportunity to improve on background processing for react-native applications. If someone were to take over and further enhance react-native-background-worker and offer support for iOS on that module, that would be a big win for the react-native ecosystem.
what about "react-native-background-timer" ?
does it works when device is in sleep mode or we exit the app?