Languages

Menu
Sites
Language
How to know if app is in background or foreground?

Hi

I want to know/intercept somehow if the app goes to the background to disable some threads. And if it comes back to the foreground...

How can I do that in a web application?

Thanks

 

 

Responses

3 Replies
Slawek Kowalski

You have use window events commone for HTML5.

Use this. Works for all Tizene phones:

 

    // Control app visibility.
    var hidden,visibilityChange;
    if (typeof document.hidden !== "undefined") {
    	hidden = "hidden";
    	visibilityChange = "visibilitychange";
    } else if (typeof document.webkitHidden !== "undefined") {
    	hidden = "webkitHidden";
    	visibilityChange = "webkitvisibilitychange";
    }
    
    function handleVisibilityChange(){
    	if (document[hidden]){
    			console.log("Page is now hidden.");
    			onAppBackground();
    	    } else {
    	    	console.log("Page is now visible.");
    	    	 onAppForeground();
    	    }
    	}
    document.addEventListener(visibilityChange, handleVisibilityChange, false);


 

Shaswati Saha
James Bond

Thank you!