언어 설정

Menu
Sites
Language
Page refresh on move to foreground - Samsung Galaxy watch wearable

I have a small app that retrieves JSON from a website connected to a remote sensor.

I am a beginner Java coder, in fact a beginner coder all round.

I have got it working ok.

The main remote sensor updates the central webserver every 15 minutes. 

If the app is open from "new" it reads the latest information from the website

If the app is already open, then a tap on the screen retrieves the latest information (I coded that with a "click" event handler.

However if the app is running but the screen has gone black (screensaver) or if I have looked at another app (ie health) and then come back, I cannot get it to have automatically refreshed. 

I have put in an event handler for "Resume" but this does not appear to be triggered. Any ideas (in simple language for a beginner!)

boatscreenclick.addEventListener("click", function(){
    	// During the data get I turn the time red, this will show if the data is slow to update.
    	document.getElementById("Time").style.color = "red";
    	BoatGetJSON();
    	// Restore the color palette after refresh has occured.
		document.getElementById("Time").style.color = "#D1D1D1";
    });
    document.addEventListener('resume', function (){
    	// Should refresh on resume. Not 100% sure this works, hence the code abover for the screen click refresh
    	document.getElementById("Time").style.color = "yellow";
    	BoatGetJSON();
    	// Restore the color palette after refresh has occured.
		document.getElementById("Time").style.color = "#D1D1D1";
    	
    });

 

답변 바로가기

Responses

2 댓글
Mark as answer
Marco Buettner

I think resume is the wrong event... try to use 'visibilitychange' as event and make depends of changing 

https://developer.mozilla.org/de/docs/Web/Events/visibilitychange

Martin LINES

Great, that worked perfectly

 

Many thanks

 

Martin