I would to create a timer in my App. I created a timer as:
var timer = document.getElementById('timer');
var rest = 90;
timer.innerHTML = rest + 's';
var interval = setInterval(function(){
if(rest <= 0){
clearInterval(interval);
}else{
rest -= 1;
timer.innerHTML = rest + 's';
}
}, 1000);
<div id='timer'></div>
But, when the user leaves my app (NOT KILL, JUST LEAVE) and go to any other app, the timer stops working.
And when he comes back to my app, the timer starts working.