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


11372
11373
# File 'Monkeybrains.rb', line 11372

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


11334
11335
# File 'Monkeybrains.rb', line 11334

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


11361
11362
# File 'Monkeybrains.rb', line 11361

def onOAuthResponse()
end

onSleepTimeObject

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

Since:

  • 2.3.0


11346
11347
# File 'Monkeybrains.rb', line 11346

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


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

def onSteps()
end

onTemporalEventObject

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

Since:

  • 2.3.0


11326
11327
# File 'Monkeybrains.rb', line 11326

def onTemporalEvent()
end

onWakeTimeObject

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

Since:

  • 2.3.0


11340
11341
# File 'Monkeybrains.rb', line 11340

def onWakeTime()
end