react-native-background-job
react-native-background-job copied to clipboard
Jobs are only executed in foreground
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
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);
}
});