Why do I see Background.registerForSleepEvent in the profiler?

When running my app in the profiler, I see a significant amount of calls to Toybox.Background.registerForSleepEvent, and also significant time spent in these calls. See the screenshot below.

Anybody knows what is up with that?

I am not calling this function in my code. The documentation says it is to register for events when the sleep time configured on the device occurs. But the method has neither inputs nor returns.

developer.garmin.com/.../Background.html

Edit: the stack trace in the profiler only points to the functions, but what both functions have in common is a call to Method.invoke. So may be related to that, though I have no clue how.

Top Replies

All Replies

  • The documentation says it is to register for events when the sleep time configured on the device occurs. But the method has neither inputs nor returns.

    It doesn't need an argument or a return value. If you call Background.registerForSleepEvent() (once) it means that the background process will be notified at the user's configured sleep time (ServiceDelegate.onSleepTime() will be called). There's a corresponding wake event, for the user's configured wake time.

    It's weird that the profiler says it was called 240 times tho.

    Does your app have a background process at all?

    If so, can you call Background.getSleepEventRegistered to check whether a sleep event was really registered?

    It's probably a bug in the profiler though.

  • Does your app have a background process at all?

    If so, can you call Background.getSleepEventRegistered to check whether a sleep event was really registered?

    It has a background process in some device configurations, but not in the one I am currently testing.

    I have to check the numbers, but roughly estimated the 240 could well concur with the number of Method.invoke calls made. There are two stack traces associated with the entry in the profiler, and both point to the two functions I have that call Method.invoke. So maybe it is really a bug in the profiler and just the shown function name is wrong.