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


11355
11356
# File 'Monkeybrains.rb', line 11355

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


11317
11318
# File 'Monkeybrains.rb', line 11317

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


11344
11345
# File 'Monkeybrains.rb', line 11344

def onOAuthResponse()
end

onSleepTimeObject

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

Since:

  • 2.3.0


11329
11330
# File 'Monkeybrains.rb', line 11329

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


11337
11338
# File 'Monkeybrains.rb', line 11337

def onSteps()
end

onTemporalEventObject

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

Since:

  • 2.3.0


11309
11310
# File 'Monkeybrains.rb', line 11309

def onTemporalEvent()
end

onWakeTimeObject

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

Since:

  • 2.3.0


11323
11324
# File 'Monkeybrains.rb', line 11323

def onWakeTime()
end