Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trouble with setTimeout: does not work while the screen is off

Hi all 😁.

I wonder if somebody could help me, please 😅

 

I am working on a code based on the open source "Kearsage time for fitbit": (https://github.com/cmspooner/Kearsarge-Time-for-Fitbit-Ionic/blob/master/app/index.js) and, I can not get the alarm to vibrate when the screen is off. I have tried the function setTimeout and It do not seems be working.

 

I have not done changes in the function wich the alarm vibrates (remaining is the amount of minutes resting for complete a period of time):

 

function updatePeriodData() {

...

...
if (remaining <= 2)

{
timeRemainingLabel.style.fill = 'fb-red';
if (!didVib){
    vibration.start("ring");
   didVib = true;
 }
 else if (remaining > 2 && didVib){
     didVib = false;
     timeRemainingLabel.style.fill = 'silver';
} else {
     timeRemainingLabel.style.fill = 'silver';
}

...

...
}

 

But I have changed the way of call the functions, I insert "the main" in a function, for example:

 

function eventHandle() {
   background.onclick = function(evt) {
   console.log("Click");
   console.log("JS memory: " + memory.js.used + "/" + memory.js.total);
...

...

if (inSched){
    weatherView.style.display = "none";
    updatePeriodData();
    periodView.style.display = "inline";
}

...

clock.ontick = () => updateClock();

updateClock();

...

...

} //end function

 

And the "main" is:

setTimeout(eventHandle, 5000); that is my only line of code on the body.

 

If you need more detailed information, I would be glade of helping.

Bye!!!

Thanks!!!!!

 

Best Answer
0 Votes
4 REPLIES 4

I didn't study closely, but did you want setInterval rather than setTimeout?

The only thing that won't happen when display is off is onclick.

Peter McLennan
Gondwana Software
Best Answer

Thanks for your response, let me check, I just hae tried with setTimeout. Thanks!

Best Answer
0 Votes

I have only tried**

Best Answer
0 Votes

Hi, sorry.

 

I have tried both functions now, and setInterval do not fire the alarm.

 

Is there any other function I can use for activate an alarm at a certain time? I do not find much information, maybe I do not know were to looking for. I still stuck with making the alarm vibrate while the screen is of.

 

Thanks!!!!!

Best Answer
0 Votes