react-native-background-job icon indicating copy to clipboard operation
react-native-background-job copied to clipboard

Jobs are only executed in foreground

Open renehauck opened this issue 7 years ago • 1 comments

First, thanks to this awesome tool :+1:

When i try this simple code:

index.android.js(outside of a class)


const myJobKey = "Hej";

BackgroundJob.register({
  jobKey: myJobKey,
   job: () => {
     setInterval(()=>{
     Vibration.vibrate(200,false)
     },2000)
   }
});

main.js(within a class)

     <Button title="start" onPress={async () => {
                    const myJobKey = "Hej";
                         BackgroundJob.schedule({
                        jobKey: myJobKey,
                        timeout: 5000
                    });
                }}>

and my app goes into the background or will be terminated, nothing happens. Back in the foreground, my phone vibrate. Same when i try it with console.log instead of Vibration.

    "react": "16.0.0-alpha.6",
    "react-native": "0.44.0",
    "react-native-background-job": "^1.2.3",

Thx

renehauck avatar Jun 12 '17 11:06 renehauck

Unfortunately setInterval does not work in the background (a React Native issue/feature). Try this instead:

BackgroundJob.register({
  jobKey: myJobKey,
   job: () => {
     Vibration.vibrate(200,false);
     }
});

vikeri avatar Jun 12 '17 14:06 vikeri