Class: Toybox::System::ServiceDelegate

Inherits:
Lang::Object show all

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.

Examples:

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);
    }
}

See Also:

Since:

  • 2.3.0

Instance Method Summary collapse

Methods inherited from Lang::Object

equals, hashCode, method, toString, weak

Instance Method Details

onGoalReached(goalType) ⇒ Object

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

Parameters:

  • goalType (Toybox::Lang::Number)

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

Since:

  • 2.3.0



9497
9498
# File 'Monkeybrains.rb', line 9497

def onGoalReached(goalType)
end

onOAuthResponseObject

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

Since:

  • 2.3.0



9524
9525
# File 'Monkeybrains.rb', line 9524

def onOAuthResponse()
end

onSleepTimeObject

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

Since:

  • 2.3.0



9509
9510
# File 'Monkeybrains.rb', line 9509

def onSleepTime()
end

onStepsObject

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

Step goals occur at 1000 step increments.

Since:

  • 2.3.0



9517
9518
# File 'Monkeybrains.rb', line 9517

def onSteps()
end

onTemporalEventObject

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

Since:

  • 2.3.0



9489
9490
# File 'Monkeybrains.rb', line 9489

def onTemporalEvent()
end

onWakeTimeObject

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

Since:

  • 2.3.0



9503
9504
# File 'Monkeybrains.rb', line 9503

def onWakeTime()
end