언어 설정

Menu
Sites
Language
how to check whether application is running in foreground or background

I'd like to check whether web application is running in foreground or background. is there any function to catch up this one?

Thank in advance.

 

Responses

7 댓글
Vikram

Hi,

You can refer to this link may be help you.

https://developer.tizen.org/community/code-snippet/web-code-snippet/how-recognize-foregound-or-background-state-application?tab=all

 

Palitsyna

Hello,

try to use visibilitychange event to check whether your app is running in foreground or background. Try following code:

document.addEventListener("visibilitychange", function() {  
    if (document.hidden) {
        console.log("background");
    } else {
        console.log("foreground");
    }
});

 

AVSukhov

Hello,

As say Palitsyna you can use webkitvisibilitychange event.

Also you may need to add background-support attribute to settings in config.xml

https://developer.tizen.org/development/guides/web-application/w3chtml5supplementary-features/performance-and-optimization/page-visibility

https://developer.tizen.org/development/tutorials/web-application/w3chtml5supplementary-features/performance-and-optimization/page-visibility

https://developer.tizen.org/development/tools/web-tools/configuration-editor#mw_setting

Seoghyun Kang

Hello,

 

You can also use the focus event.  Please refer the following code.

window.addEventListener('blur',function(){
    // TODO
    stateBackground = true;
});

window.addEventListener('focus',function(){
    // TODO
    stateBackground = false;
});

 

Palitsyna

Hello,

as AVSukhov said, you need to add background-support attribute to settings in config.xml as shown below.

/* Web application execution is not suspended */
/* when the application is sent to the background */
<tizen:setting background-support="enable" />

More info here: https://developer.tizen.org/dev-guide/web/2.3.0/org.tizen.mobile.web.appprogramming/html/ide_sdk_tools/web_config_ext.htm#setting

Alex Dem

Hi,
fyi: here is even tutorial regarding "visibilitychange": https://developer.tizen.org/development/articles/application-visibility
Alexey.

Vikram

Hi,

I found a interesting example, http://www.samdutton.com/pageVisibility/

When you add new tab page, the music and animation stopped.Switch to back, the animation will continue again.