Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native, setInterval stopped when activity is on pause

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.

like image 744
Charly berthet Avatar asked Nov 27 '22 04:11

Charly berthet


1 Answers

This question is a copy to the following:

How can I run background tasks in React Native?

The following answer is written: Currently, there is, unfortunately, no support for background tasks of any kind. The feature you are referring to would be a background timer. Such a timer is this product plain (a feature request) for react native, you may upvote it to show an increased demand for this feature.

(There is no update yet. As far as i know)

like image 57
Jonathan Stellwag Avatar answered Nov 28 '22 16:11

Jonathan Stellwag