I am developing a react native app. For one of the task, I need to use javascript setInterval
function, but it get's stop when the app is in the background. Can anyone guide me, why it is stopping? Any solution to it?
My Code:
let startTimer = setInterval(() => {
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
this.setState({ remainMin: minutes, remainSec: seconds });
if (--timer < 0) {
this.handelTimerStop();
timer = duration;
this.setState({ isResend: true });
}
}, 1000);