react-native-background-job
react-native-background-job copied to clipboard
Kill jobs when app gets closed
I've been trying to cancelAll jobs after the user closes the app and I don't really see an easy way to do this. My current approach is relaying in the fact that every time I close the app the variables inside the main javascript environment gets reseted.
// Make this variable true inside your main component, this way when the job
// gets executed we know the user have opened the app.
let control = false
function myJob(){
// This variable will be false when the job gets called and the app have been
// closed since the variable resets it's value.
if(!control) {
CANCELALL()
}
//
// Do what you want here.
}
Do you have an example on how to do this easier ? Maybe it should be an option in schedule? Thank you for this amazing library.
Hi @dev-andremonteiro This library is used to schedule background jobs even if the user closes the app. I didn't understand your usage .
Have a look at the app states here : https://facebook.github.io/react-native/docs/appstate
I was trying to make this run only while the app was on the background and once the user closes it, it stops working. That's my use case.
use this library instead -> https://github.com/ocetnik/react-native-background-timer
i think i must use this library too, it does not work and no error tip,