Languages

Menu
Sites
Language
Running an app in background - timer

Hi

I am creating a timer app which does time laps.
​I could set the app to foreground all the time, so it will not quit, but that is unnecessary battery consuming.

But when I go to another app, my app gets quit after some few minutes running in the background...

How can I prevent that? It is running a timer and using GPS data (which it should also in the background)

Thanks

Responses

1 Replies
Iqbal Hossain

hi James Bond

You may be done something not correct. You have to enable background support. It works fine when i run another app or put off the screen etc . 

Here is an simple example, 

html

 <div id="main" class="page">
    <div class="contents">
        <span id="demo" >Background App</span>
    </div>
</div>

js

window.onload = function() {
    // TODO:: Do your initialization job

    // add eventListener for tizenhwkey
    document.addEventListener('tizenhwkey', function(e) {
        if (e.keyName === "back") {
            try {
                tizen.application.getCurrentApplication().exit();
            } catch (ignore) {}
        }
    });
    var myVar = setInterval(myTimer, 1000);
    var counter = 0;
    function myTimer() {
        counter += 1;
        document.getElementById("demo").innerHTML = counter;
    }
   
};

config

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns:tizen="http://tizen.org/ns/widgets" xmlns="http://www.w3.org/ns/widgets" id="http://yourdomain/BackgroundTimerWeb" version="1.0.0" viewmodes="maximized">
    <tizen:application id="XXXXXX.BackgroundTimerWeb" package="XXXXXX" required_version="2.4"/>
    <content src="index.html"/>
    <feature name="http://tizen.org/feature/screen.size.all"/>
    <icon src="icon.png"/>
    <name>BackgroundTimerWeb</name>
    <tizen:profile name="mobile"/>
    <tizen:setting screen-orientation="portrait" context-menu="enable" background-support="enable" encryption="disable" install-location="auto" hwkey-event="enable"/>
</widget>

-thanks