How to use React Native Foreground Service @v2 🚀

Raja Osama
JavaScript in Plain English
2 min readOct 30, 2020

--

Forground service that you can use to create an always on Background task in React Native. Foreground service is a kind of service in Android that has a notification that can not be removed until the foreground service is closed, and because of this, you can run a background task with the help of headless JS.

With the latest update of the v2 of React native foreground service, things are more easier and convenient now, React native foreground service now lets you easily install and linked RN foreground service with your application with just 2 steps of installation.

The purpose of this article is to show you how you can easily work Install foreground Service in your application and use it as per your requirement.

If you rather watch a video, below is the link for the RN installation process and how you can easily install it and link it. https://www.youtube.com/watch?v=t5LQdbvjufM

Check it out 👆

To Install the Library and attach it to your project, you can easily install it within 2 to 3 steps. Let's get to it.

Step 1

Installing the library with

npm i @supersami/rn-foreground-service

or

yarn add @supersami/rn-foreground-service

Step 2

Just run this command once and see the magic.

node node_modules/@supersami/rn-foreground-service/postinstall.js

In any case, if the above doesn’t link your application correctly, you can try on manual linking of the application at the Installation Documentation

Step 3

In your root, Index.js file. Paste the following code.

import ReactNativeForegroundService from "@supersami/rn-foreground-service";
ReactNativeForegroundService.register();

The above code will register an initial headless task, which will be the first layer, over which, you can add as many tasks as you desire and they all will execute seamlessly.

Now All you have to do is to register a task and start the service, Follow the documentation below to under more about it : How to use React Native Foreground Service v2@ (rajaosama.me)

Thank you ! 🙌

More content at PlainEnglish.io.

Sign up for our free weekly newsletter. Follow us on Twitter, LinkedIn, YouTube, and Discord.

--

--

👋 Hi, I'm Raja Osama, a polyglot rockstar software engineer who loves to create fascinating applications using JavaScript-based tech stack. 💻