DEV Community

EchoEye
EchoEye

Posted on

Why's managing background tasks in react native so difficult?

Hello React Native developers! So, According to the official react native docs, the only way to implement background tasks is by using HeadlessJS which only works on android. What's confusing is that popular apps like Instagram, Facebook are built with react native and they definitely handle background tasks on both android and iOS devices pretty well. Since this issue seems resolved, is there a reason why their solution hasn't been released as a package for other react native developers to use and integrate seamlessly into their react native applications. After-all, react native is a product of Facebook and I haven't been able to find a perfectly working solution that works really well on both platforms.

Top comments (3)

Collapse
 
wynch profile image
vincent barthelemy

only solution is to go native, write native module on iOS that duplicates the logic you need in JS realm, while respecting the numerous constraints it has on background execution (no long running task, GPS or voip apps have less constraints, for other tasks you can’t wake up the os more frequently than once every 15 mn, like in react-native-background-task (github.com/jamesisaac/react-native...)

Collapse
 
echoeyecodes profile image
EchoEye

yea true.. but definitely react-native-background-task isn't what is used to power the background services for Instagram/Facebook and they don't have that constraint of a 15-minute interval schedule which makes me wonder why their implementation isn't provided as a global package for the react native community.

Collapse
 
wynch profile image
vincent barthelemy

This constraint is native, wether you use react-native or not you have it.
They used to have a hack with long running empty audio to prevent the OS from shutting down the app, but not anymore. Other things that can wake your app in background: remote notifications.
Appart from that , how do you know they don't have these constraints? What tests did you do that convinced you otherwise?