Languages

Menu
Sites
Language
Web app running in the background

Hi all,

I am developing an app, which should run in the background when the screen is off. I have added 

<tizen:setting background-support="enable" />

to the config.xml

Everything work fine when I debug it on the emulator and on my Gear Fit 2, but when I disconnect the GF2 from Tizen Studio and start the app, it is no longer running in the background. The app pauses as if I haven't enabled background-support.

 

Should I be worried? How is this even possible?

Responses

5 Replies
André Reus

hi Nikolay Mihaylov ~

You may be done something not correct. I have checked it. 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" >Pause</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 

Nikolay Mihaylov

Hi Andre,

Thanks for your reply. 

There are a couple of differences between your example and my case.

 

The required version for my project is 2.3.2. I have tried with 2.4 aswell, but the results are the same.

My profile is wearable, I'm developing for Gear and testing it on a Gear Fit 2 device. I have no way of testing it on an actual Tizen mobile device.

<tizen:profile name="wearable"/>

Otherwise everything else seems the same.

 

The problem appears only on my Gear Fit 2 device and only when I disconnect it form Tizen Studio. When connected to the IDE (debugging) it works just as intended.

Marco Buettner

Dont forget that the Gear Fit 2 isnt official supported by Tizen Studio/SDK and you have no opportunity to distribute your app via TizenStore... fyi

Nikolay Mihaylov

Hi Marco,

my intention is to distribute the app through the Galaxy App store.

But even if it is not support, I cannot understand how and why it can run perfectly when connected to the Studio and not when disconnected.

It seems as if the background-support part is failing somehow.

Nikolay Mihaylov

I finally understood what is going on here.

 

The problem occurs only when the device is not connected to the Tizen Studio and the screen goes off. In this case the CPU goes into "sleep" mode and is not running anymore.

 

The background-support setting keeps the app running in the background, but only if the CPU is awake. When connected to the Tizen Studio the CPU does not go into sleep mode even if the screen is off (debugger, console output, etc. must keep going), hence the different behaviour of the app in that case.

 

Long story short, if you want the app to run even if the screen is off (CPU is in sleep mode), you have to use the Power API and request CPU_AWAKE

tizen.power.request("CPU", "CPU_AWAKE");

You need also the respective privileges in the config.xml

<tizen:privilege name="http://tizen.org/privilege/power"/>

 

-Cheers