onNotification method

  1. @mustCallSuper
  2. @override
void onNotification()
override

Callback from the OS when this task is clicked by the user in the OS notification system.

Resumes the background sensing. When the background sensing pauses, the task is marked as done.

Implementation

@mustCallSuper
@override
void onNotification() {
  super.onNotification();
  onStart();

  // Listen to when the background sensing pauses.
  // We do this because this background sensing task is never explicitly
  // marked as done - it just runs until the background sensing pauses.
  backgroundTaskExecutor.stateEvents
      .where((state) => state == ExecutorState.Paused)
      .listen((state) {
        debug(
          '$runtimeType - Background sensing has paused - making this user task done.',
        );
        onDone();
      });
}