Module: Toybox.Background
Overview
Background events are special events that trigger in the background when either certain system events occur, such as when an activity goal has been met, or at certain times (called temporal events). This allows an application to update its data even when the application is not active.
See Also:
Classes Under Namespace
Classes: ExitDataSizeLimitException, InvalidBackgroundTimeException, MessageSizeLimitException
Instance Method Summary collapse
-
deleteActivityCompletedEvent() as Void
Stops the application from receiving activity completed events.
-
deleteGoalEvent(goalType as Application.GoalType) as Void
Remove the active goal background event of specified type for the application.
-
deleteOAuthResponseEvent() as Void
Remove the OAuth response background event.
-
deletePhoneAppMessageEvent() as Void
Stops the application from receiving background phone app messages.
-
deletePushNotificationEvent() as Void
Stops the application from receiving silent and actionable push notifications.
-
deleteSleepEvent() as Void
Remove the active sleep background event for the application.
-
deleteStepsEvent() as Void
Remove the active steps background event for the application.
-
deleteTemporalEvent() as Void
Remove the active temporal background event for the application.
-
deleteWakeEvent() as Void
Remove the active wake background event for the application.
-
exit(backgroundData as Application.PropertyValueType) as Void
Terminates the current background process.
-
getActivityCompletedEventRegistered() as Lang.Boolean
Get whether a background event is registered with registerForActivityCompletedEvent().
-
getBackgroundData() as Application.PropertyValueType
Get data previously saved by a background process.
-
getGoalEventRegistered(goalType as Application.GoalType) as Lang.Boolean
Get whether a background event is registered with registerForGoalEvent().
-
getLastTemporalEventTime() as Time.Moment or Null
Get the time the last temporal background event was triggered.
-
getOAuthResponseEventRegistered() as Lang.Boolean
Get whether a background event is registered with registerForOAuthResponseEvent().
-
getPhoneAppMessageEventRegistered() as Lang.Boolean
Get whether a background event is registered with registerForPhoneAppMessageEvent().
-
getPushNotificationEventRegistered() as Lang.Boolean
Get whether a background event is registered with registerForPushNotificationEvent().
-
getSleepEventRegistered() as Lang.Boolean
Get whether a background event is registered with registerForSleepEvent().
-
getStepsEventRegistered() as Lang.Boolean
Get whether a background event is registered with registerForStepsEvent().
-
getTemporalEventRegisteredTime() as Time.Moment or Time.Duration or Null
Get the Moment or Duration with which a background event is registered by registerForTemporalEvent().
-
getWakeEventRegistered() as Lang.Boolean
Get whether a background event is registered with registerForWakeEvent().
-
registerForActivityCompletedEvent() as Void
Registers the application to receive an event whenever an activity is completed.
-
registerForGoalEvent(goalType as Application.GoalType) as Void
Register a background event that triggers when the user reaches a specified goal.
-
registerForOAuthResponseEvent() as Void
Registers a background event that triggers each time an OAuth login request completes and the token becomes available on the system for use.
-
registerForPhoneAppMessageEvent() as Void
Registers the application to receive an event whenever a phone app message is received.
-
registerForPushNotificationEvent() as Void
Registers the application to receive silent and actionable push notifications.
-
registerForSleepEvent() as Void
Register a background event that triggers at the sleep time configured on the device.
-
registerForStepsEvent() as Void
Registers a background event that triggers each time a multiple of 1000 steps is reached.
-
registerForTemporalEvent(time as Time.Moment or Time.Duration) as Void
Register a background event that triggers at a specific time or at a regular interval.
-
registerForWakeEvent() as Void
Register a background event that triggers at the wake time configured on the device.
-
requestApplicationWake(message as Lang.String) as Void
Display a confirmation dialog requesting to launch the application to which the background task belongs.
Instance Method Details
deleteActivityCompletedEvent() as Void
Stops the application from receiving activity completed events.
deleteGoalEvent(goalType as Application.GoalType) as Void
Remove the active goal background event of specified type for the application.
deleteOAuthResponseEvent() as Void
Remove the OAuth response background event.
deletePhoneAppMessageEvent() as Void
Stops the application from receiving background phone app messages.
deletePushNotificationEvent() as Void
Stops the application from receiving silent and actionable push notifications.
deleteSleepEvent() as Void
Remove the active sleep background event for the application.
deleteStepsEvent() as Void
Remove the active steps background event for the application.
deleteTemporalEvent() as Void
Remove the active temporal background event for the application.
deleteWakeEvent() as Void
Remove the active wake background event for the application.
exit(backgroundData as Application.PropertyValueType) as Void
Terminates the current background process.
All background processes should call this method when they have completed the desired tasks. Data passed to this method will either be passed immediately to the active application if it is running, or will be saved and passed to the application the next time it runs. Data must be one of the following types:
Arrays and Dictionaries may contain null
values or any of the above
listed types. If no data should be passed to the main process, null
may
be specified.
This method will exit if called by a background process, but will do nothing if called by the main application process.
getActivityCompletedEventRegistered() as Lang.Boolean
Get whether a background event is registered with registerForActivityCompletedEvent()
getBackgroundData() as Application.PropertyValueType
Get data previously saved by a background process.
Data is delivered via
AppBase.onBackgroundData(),
and is reset to null
once data has been delivered to the main process.
This method always returns null
in the main application's process.
getGoalEventRegistered(goalType as Application.GoalType) as Lang.Boolean
Get whether a background event is registered with registerForGoalEvent().
getLastTemporalEventTime() as Time.Moment or Null
Get the time the last temporal background event was triggered.
This is useful for ensuring new events are not scheduled within the five minute minimum time allowed between temporal events.
getOAuthResponseEventRegistered() as Lang.Boolean
Get whether a background event is registered with registerForOAuthResponseEvent()
getPhoneAppMessageEventRegistered() as Lang.Boolean
Get whether a background event is registered with registerForPhoneAppMessageEvent()
getPushNotificationEventRegistered() as Lang.Boolean
Get whether a background event is registered with registerForPushNotificationEvent()
getSleepEventRegistered() as Lang.Boolean
Get whether a background event is registered with registerForSleepEvent().
getStepsEventRegistered() as Lang.Boolean
Get whether a background event is registered with registerForStepsEvent().
getTemporalEventRegisteredTime() as Time.Moment or Time.Duration or Null
Get the Moment or Duration with which a background event is registered by registerForTemporalEvent().
getWakeEventRegistered() as Lang.Boolean
Get whether a background event is registered with registerForWakeEvent().
registerForActivityCompletedEvent() as Void
Registers the application to receive an event whenever an activity is completed.
registerForGoalEvent(goalType as Application.GoalType) as Void
Register a background event that triggers when the user reaches a specified goal.
registerForOAuthResponseEvent() as Void
Registers a background event that triggers each time an OAuth login request completes and the token becomes available on the system for use.
This event is triggered when a OAuth response is received by the system.
registerForPhoneAppMessageEvent() as Void
Registers the application to receive an event whenever a phone app message is received.
registerForPushNotificationEvent() as Void
Registers the application to receive silent and actionable push notifications.
registerForSleepEvent() as Void
Register a background event that triggers at the sleep time configured on the device.
registerForStepsEvent() as Void
Registers a background event that triggers each time a multiple of 1000 steps is reached.
This event is triggered only by device-recorded steps, and will not trigger based on synced steps.
registerForTemporalEvent(time as Time.Moment or Time.Duration) as Void
Register a background event that triggers at a specific time or at a regular interval.
Temporal background events may be registered to run at a specific point in time by providing a Moment at which the event should trigger, or may be registered to run at a periodically by specifying an interval Duration. If a temporal event is scheduled for a time in the past, the event will trigger immediately.
Temporal events cannot be set to occur less than 5 minutes after the last temporal event occurred. For watch-apps and widgets the 5 minute restriction is cleared on application startup if the event was specified using a Moment.
Only one temporal event may be registered at a time. Calling
registerForTemporalEvent
will overwrite any previously registered
temporal events.
registerForWakeEvent() as Void
Register a background event that triggers at the wake time configured on the device.
requestApplicationWake(message as Lang.String) as Void
Display a confirmation dialog requesting to launch the application to which the background task belongs.
If the dialog is confirmed, the application will open. If the dialog is declined, the application will not open and the dialog will be dismissed. This request is only valid for widget or device app background tasks, and will be ignored by watch face apps. Background.exit() must be called at some point in the background process after this method is invoked because the confirmation dialog will only trigger after the background task exits.