- The order in which the background service calls functions is this:
AppBase::onStart
AppBase::getServiceDelegate
BackGroundService::initialize
BackgroundService::onTemporalEvent
AppBase::onStop
So the AppBase's onStart and onStop functions are called every time the service runs.
I'm assuming that when the user switches from the watchface to something else (flicking up-down to other widgets, starting activity, etc.) the AppBase onStop would be called, but how am I supposed to differentiate between a call from the background service and the foreground?
I'd like to call
Background.deleteTemporalEvent();
in onStop() so that when the watchface is not active the background service does not run.And when the watchface starts again, I would just start it with
Background.registerForTemporalEvent(new Time.Duration(5 * 60));