DEV Community

Cover image for Background Processing for React Native Applications in 2022
Chris Dougherty
Chris Dougherty

Posted on • Updated on

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.


React Native Background Fetch

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

  • Well maintained
  • Works on both android AND iOS

Disadvantages

  • Only a periodic worker (no support for queue)
  • Only runs once every 15 minutes. There is no way to speed this up.
  • Not very many features.

React Native Background Task

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

  • Works on both android AND iOS

Disadvantages

  • Not well maintained
  • Only offers a periodic worker that runs once every 15 minutes.
  • Has some pretty restrictive limitations such as tasks not being run while the app is in the foreground for Android and tasks are not able to run if the user manually closes the app on iOS.

React Native Background Worker

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

  • Offers queue AND periodic worker options.
  • Includes more functionality as compared to other options.

Disadvantages

  • Not well maintained.
  • Can only be used for android.

Headless JS

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

  • Well maintained and supported by react-native.
  • Customizable retry policy.

Disadvantages

  • Requires that you write some native code.
  • Does not have a whole lot of features such as managing periodic or queue work.
  • Only works on Android (NOT on iOS)

(Coming Soon) React Native Background Queue Processor

...


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.

Top comments (0)