11-12-2017 19:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-12-2017 19:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
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();
Answered! Go to the Best Answer.
Accepted Solutions
11-15-2017 14:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-15-2017 14:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
try:
display.onchange = function() { if (display.on) {
console.log("ON");
updateSteps();
} }
11-14-2017 12:55
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-14-2017 12:55
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
The display onchange event doesn't fire if the display is already on.
Just call updateSteps() when your app launches.
display.onchange = () => updateSteps(); updateSteps();

11-15-2017 12:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-15-2017 12:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.

11-15-2017 13:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-15-2017 13:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
You need both, as per my example.
One fires when the display comes on, the other fires when the app is launched.

11-15-2017 13:50
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-15-2017 13:50
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I currently have both, but the display coming on one doesn't seem to be firing.

11-15-2017 13:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-15-2017 13:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Are you importing display?
import { display } from "display";
Also, check you don't have another variable named display.

11-15-2017 14:04
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-15-2017 14:04
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
It is importing, and no other display variables.

11-15-2017 14:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-15-2017 14:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
put a console.log inside the updateSteps(), does that output when the display wakes?

11-15-2017 14:40
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-15-2017 14:40
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Nope, it only logs when I close and then re-open the app. Not from the screen wake.
//Update steps display.onchange = () => updateSteps(); updateSteps();

11-15-2017 14:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-15-2017 14:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
try:
display.onchange = function() { if (display.on) {
console.log("ON");
updateSteps();
} }
11-15-2017 14:49
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-15-2017 14:49
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
That seemed to do it. 🙂
Confirmed that the actual steps updated on the watchface as well.

