Class: Toybox.System.ServiceDelegate

Overview

ServiceDelegate is a class used to service Background events.

This class is used as the main entry point for background processes. A callback function within the delegate can be used to initiate other system events (e.g. Communications), but only the delegate function is guaranteed to complete. The Background process may be shut down at any time to handle higher priority processes.

See Also:

Example:

using Toybox.Background;
using Toybox.Communications;
using Toybox.System;

(:background)
class MyServiceDelegate extends System.ServiceDelegate {
    // When a scheduled background event triggers, make a request to
    // a service and handle the response with a callback function
    // within this delegate.
    function onTemporalEvent() {
        Communications.makeWebRequest(
            "https://myrequesturl.com",
            {},
            {},
            method(:responseCallback)
        );
    }

    function responseCallback(responseCode, data) {
        // Do stuff with the response data here and send the data
        // payload back to the app that originated the background
        // process.
        Background.exit(backgroundData);
    }
}

Since:

API Level 2.3.0

Instance Method Summary collapse

Instance Method Details

onActivityCompleted(activity as { :sport as Activity.Sport, :subSport as Activity.SubSport }) as Void

The callback method that is triggered when an activity is completed

Parameters:

  • activity(Lang.Dictionary)

    A dictionary containing information about the completed activity.

    • :sport(Activity.Sport)

      The primary sport of the completed activity.

    • :subSport(Activity.SubSport)

      The sport subcategory of the completed activity.

Since:

API Level 3.0.10

onGoalReached(goalType as Application.GoalType) as Void

A callback method that is triggered in the background when a fitness goal is reached.

Parameters:

  • goalType(Application.GoalType)

    An Application.GOAL_TYPE_* value, representing the goal type that is being registered.

Since:

API Level 2.3.0

onOAuthResponse() as Void

The callback method that is triggered in the background when an OAuth response is received from the system

Since:

API Level 2.3.0

onPhoneAppMessage(msg as Communications.PhoneAppMessage) as Void

The callback method that is triggered when a phone app message arrives for this app

Parameters:

Supported Devices:

Since:

API Level 3.2.0

onSleepTime() as Void

The callback method that is triggered in the background at the configured sleep time.

Since:

API Level 2.3.0

onSteps() as Void

The callback method that is triggered in the background when a step goal is reached.

Step goals occur at 1000 step increments.

Since:

API Level 2.3.0

onTemporalEvent() as Void

A callback method that is triggered in the background when time-based events occur.

Since:

API Level 2.3.0

onWakeTime() as Void

A callback method that is triggered in the background at the configured wake time.

Since:

API Level 2.3.0


Generated Sep 23, 2024, 3:32:49 PM