fx-fotos icon indicating copy to clipboard operation
fx-fotos copied to clipboard

How to run a task when app is in background

Open ghorbani-m opened this issue 2 years ago • 2 comments

For this purpose, I used the combination of react-native-background-action and react-native-background-fetch. I configured the BackgroundFetch to run every 15 minutes and call a function, inside of the function I tried to start a "BackgroundJob". Something like this :

 if (!BackgroundJob.isRunning())
        await BackgroundJob.start<TaskParams>(backgroundTask, {
          ...defaultOptions,
          parameters: {
            callback: options?.callback,
            assets,
          },
        })

But when the app runs in the background I get this error message: [Error: Not allowed to start service Intent { cmp='packgeName'/com.asterinet.react.bgactions.RNBackgroundActionsTask (has extras) }: app is in background uid UidRecord{3090e14 u0a296 TRNB idle change:uncached procs:0 seq(0,0,0)}]

ghorbani-m avatar Jun 04 '22 10:06 ghorbani-m

I guess we can not start a service while the app service is running, actually, when the react-native-background-fetch service is running we can not run the react-native-background-action service inside that.

ghorbani-m avatar Jun 06 '22 13:06 ghorbani-m

Hey @ghorbani-m, yeah I also agree with you. Running tasks in the background with react-native is always a big deal. Maybe we can discuss this in a meeting.

emadbaqeri avatar Jun 06 '22 13:06 emadbaqeri