Languages

Menu
Sites
Language
Method setTimeout() doesn't work if a device is sleeping. Works if time isn't long (seconds, minutes). Doesn't work if > 1 hour

Method setTimeout() doesn't work if a device is sleeping. Is it normal?

Edited by: Anonymous on 03 May, 2019

Responses

11 Replies
Onur Şahin

Yes it is normal. Use alarm api if you want to wake cpu up.

Hi! Thanks for your reply!

Timeout and Interval don't work if time is over 1 hour :( how to overcome? (

background-support=enable + alarm

Armaan-Ul- Islam

As I see in this post JavaScript setTimeout(func(),1 hour)  should not have any issue, it may work fine.

https://developer.tizen.org/forums/web-application-development/method-settimeout-doesnt-work-if-device-sleeping.

 

# One possibility is that system is killing your  process when it is being Idle for a long time (like an hour).

 

# You can try requesting CPU to be awaken for the process by using Power API. Don’t forget to release the resource when you are done.

tizen.power.request("CPU ", " CPU_AWAKE");
// after completation
tizen.power.release("CPU");
<tizen:privilege name="http://tizen.org/privilege/power"/>

 Add power privilege on your config.xml

Link:

https://developer.tizen.org/ko/development/guides/web-application/device-settings-and-systems/power-states?langredirect=1

https://developer.tizen.org/ko/development/api-references/web-application?redirect=/dev-guide/2.4/org.tizen.web.apireference/html/device_api/mobile/tizen/power.html&langredirect=1

(Requesting CPU for long time like an hour seems not an Ideal solution)


 

Thanks! I haven't tested it yet.

It may not work in theory if system is killing the process at some time and stops the timer to count.

Where should I put CPU_AWAKE request? In the setTimeout body? In this case who gonna awake this Timeout? Maybe this request should be turn ON while Timeout is set and it is counting and release it when Timeout is over.

Or maybe Timeout counts but can't do nothing when time is elapsed? But it's Illogically, because Timeout will implement methods it has if it can counts. It means that system doesn't sleep.

Armaan-Ul- Islam

Make the request anywhere in your js file, preferebly in the beginning.

 tested it with the request in the Timeout body. It doesn't work and it's logicaly as I've supposed.

Now I gonna try this way:

tizen.power.request("CPU", "CPU_AWAKE");
setTimeout(function() {
tizen.power.release("CPU");
}, 3600 * 1000);

In theory system shouldn't fall asleep until Timeout is elapsed and releases CPU.

But I think it's a strange way to overcome this problem because of battery draining.

I found out in what time system kills application processes. This time is 10 minutes.

I was testing the last way when watch screen turned ON and I saw a message "APP_NAME is using excessive battery power. Close app?".

So tizen.power.request("CPU", "CPU_AWAKE") is bad way to overcome Timeout problem. :(

I found out the best way how to replace Timeout and battery draining.

It's using The Time API’s TimeDuration which provides the difference method to calculate the difference between two date or time events without having to bother about the difference in the event units. TimeDuration.difference method accepts another TimeDuration object and performs a (this object  parameter object)operation, and returns a TimeDuration object.

// Compute event1.duration - event2.duration
var diff = event1.duration.difference(event2.duration);
if (diff.length > 0)
console.log("Event1 is longer than Event2");
else if (diff.length = 0)
console.log("Event1 is as long as Event2");
else
console.log("Event1 is shorter than Event2");

So now I can refuse using background-support, alarm, CPU.

Application can fall asleep. Time sets once and in the next execution time will be compared.

Unfortunately this way won't be sutibale if you need to awake application but in my case it's perfect because I wan't to do something when you turn on watch and the time is run out.

Armaan-Ul- Islam

Good finding. Thanks for sharing.

I tested it with the request in the Timeout body. It doesn't work and it's logicaly as I've supposed.

Now I gonna try this way:

tizen.power.request("CPU", "CPU_AWAKE");
setTimeout(function() {
tizen.power.release("CPU");
}, 3600 * 1000);

In theory system shouldn't fall asleep until Timeout is elapsed and releases CPU.

But I think it's a strange way to overcome this problem because of battery draining.