skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. 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====>

    import BackgroundTimer from "react-native-background-timer";
    
    useEffect(() => {
        const timeoutId = BackgroundTimer.runBackgroundTimer(async () => {
          callYourFunction(); // Call your Function Here
        }, 10000);
        
       // 10000 is 10 Seconds
    
        return () => BackgroundTimer.clearInterval(timeoutId);
      }, []);
    

    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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search