In android mobile app developed in Ionic 5 Cordava, we want to call some rest api when mobile screen is off, but not any one api is called during that time, we want to call that api every 5 seconds.
We have added below code in App.components
document.addEventListener('visibilitychange', () => {
console.log('checking visibilychange:', document.visibilityState);
if (document.visibilityState === 'hidden') {
console.log('App is in the background');
console.log('In Background');
// this.backgroundMode.setEnabled(true);
console.log('this.login == true', this.login == true);
this.bluetoothService.backgroundMode = true;
this.startBackgroundTask();
setTimeout(() => {
this.startBackgroundTask();
}, 5000);
});```
startBackgroundTask() {
this.apiCallInProgress = false;
// this.backgroundMode.enable();
console.log('this.backgroundMode.enable()', this.backgroundMode.isEnabled);
console.log('!this.apiCallInProgress', this.apiCallInProgress);
if (!this.apiCallInProgress) {
this.apiCallInProgress = true;
this.startBackgroundGeolocation();
setTimeout(() => {
this.apiCallInProgress = false;
}, 5000);
}
}
api is not called during this time. I am not sure whether I am missing anything
New contributor
Sridevi R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.