Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Update steps on screen wake

ANSWERED

I'm trying to have to steps update in my watchface whenever the screen wakes up. It appears to be working whenever I view my watch, my steps are displayed, and up to date. But if I open another app, and then go back to the watch screen, my steps are no longer displayed, but have disappeared entirely.

This is the code I was using to have the steps update:

function updateSteps() {
  let steps = (userActivity.today.local.steps.toLocaleString() || 0) + " STEPS";
  mySteps.text = `${steps}`;
}
display.onchange = () => updateSteps();
Best Answer
1 BEST ANSWER

Accepted Solutions

try:

display.onchange = function() {
  if (display.on) {
console.log("ON");
updateSteps();
} }

View best answer in original post

Best Answer
10 REPLIES 10

The display onchange event doesn't fire if the display is already on.

 

Just call updateSteps() when your app launches.

 

display.onchange = () => updateSteps();
updateSteps();
Best Answer
0 Votes

Thanks @JonFitbit. But I had previously tried this method, and the steps never seem to update on their own.
If I use both lines that you suggested, then the steps only actually update when I go back to the watchface from another app. For example, my steps will remain the same, no matter how many times the screen wakes up, UNTIL I open the 'Today' app, and then go back to the main watchface. Only then will the steps actually update on that screen.

Best Answer
0 Votes

You need both, as per my example.

One fires when the display comes on, the other fires when the app is launched.

Best Answer
0 Votes

I currently have both, but the display coming on one doesn't seem to be firing.

Best Answer
0 Votes

Are you importing display?

 

import { display } from "display";

Also, check you don't have another variable named display.

Best Answer
0 Votes

It is importing, and no other display variables.

Best Answer
0 Votes

put a console.log inside the updateSteps(), does that output when the display wakes?

Best Answer
0 Votes

Nope, it only logs when I close and then re-open the app. Not from the screen wake. 
Capture.PNG

//Update steps
display.onchange = () => updateSteps();
updateSteps();
Best Answer
0 Votes

try:

display.onchange = function() {
  if (display.on) {
console.log("ON");
updateSteps();
} }
Best Answer

That seemed to do it. 🙂 

Confirmed that the actual steps updated on the watchface as well.
Capture.PNG

Best Answer
0 Votes