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

onActivityCompleted(activity) ⇒ Object

The callback method that is triggered when an activity is completed

Parameters:

Options Hash (activity):

Since:

  • 3.0.10


10035
10036
# File 'Monkeybrains.rb', line 10035

def onActivityCompleted(activity)
end

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


9997
9998
# File 'Monkeybrains.rb', line 9997

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


10024
10025
# File 'Monkeybrains.rb', line 10024

def onOAuthResponse()
end

onSleepTimeObject

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

Since:

  • 2.3.0


10009
10010
# File 'Monkeybrains.rb', line 10009

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


10017
10018
# File 'Monkeybrains.rb', line 10017

def onSteps()
end

onTemporalEventObject

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

Since:

  • 2.3.0


9989
9990
# File 'Monkeybrains.rb', line 9989

def onTemporalEvent()
end

onWakeTimeObject

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

Since:

  • 2.3.0


10003
10004
# File 'Monkeybrains.rb', line 10003

def onWakeTime()
end