react-native-background-actions
react-native-background-actions copied to clipboard
service dies after a day
Hello
I have installed my app as an APK on my phone (Android) and what I see is that the service just automatically dies/stops after around 24 hours, without any reboot or anything.
This is my current code:
const RunCronjob = async () => {
const sleep = (time) => new Promise((resolve) => setTimeout(() => resolve(), time));
const myappBackgroundService = async (taskDataArguments) => {
const { delay } = taskDataArguments;
await new Promise( async (resolve) => {
for (let i = 0; BackgroundService.isRunning(); i++) {
// This is so it lets the dashboard get the data so dashboard loading work
setTimeout(() => dataSyncCronJob(), 10000);
dataSyncNotificationCronJob();
//twice per day
if (moment().format('HH') === '11' || moment().format('HH') === '23') {
twicePerDayCronJob();
}
await sleep(delay);
}
});
};
const options = {
taskName: 'myappCrons',
taskTitle: 'myapp',
taskDesc: '',
taskIcon: {
name: 'ic_myapp_notification',
type: 'drawable',
},
color: '#ff8e23',
parameters: {
delay: 4 * 60 * 1000
},
};
if (!BackgroundService.isRunning()) {
await BackgroundService.start(myappBackgroundService, options);
await BackgroundService.updateNotification();
}
}
Any help is much appreciated!