onActivityChange static method

void onActivityChange(
  1. dynamic callback(
    1. ActivityChangeEvent
    )
)

Subscribe to changes in motion activity.

Your callback will be executed each time the activity-recognition system receives an event (still, on_foot, in_vehicle, on_bicycle, running).

Example

BackgroundGeolocation.onActivityChange((ActivityChangeEvent event) {
  print('[onActivityChange] ${event}');
});

Implementation

static void onActivityChange(Function(ActivityChangeEvent) callback) {
  if (_eventsActivityChange == null) {
    _eventsActivityChange = _eventChannelActivityChange
        .receiveBroadcastStream()
        .map((dynamic event) {
      return ActivityChangeEvent(event['activity'], event['confidence']);
    });
  }
  _registerSubscription(_eventsActivityChange!.listen(callback), callback);
}