Package io.flutter.embedding.engine.plugins.service

## Interface ServiceControlSurface

-     public interface ServiceControlSurface

  Control surface through which a `Service` attaches to a `FlutterEngine`.

  A `Service` that contains a `FlutterEngine` should coordinate itself with the `FlutterEngine`'s `ServiceControlSurface`.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `attachToService​(Service service, androidx.lifecycle.Lifecycle lifecycle, boolean isForeground)` | Call this method from the `Service` that is running the `FlutterEngine` that is associated with this `ServiceControlSurface`.
    `void` | `detachFromService()` | Call this method from the `Service` that is attached to this `ServiceControlSurfaces`'s `FlutterEngine` when the `Service` is about to be destroyed.
    `void` | `onMoveToBackground()` | Call this method from the `Service` that is attached to this `ServiceControlSurface`'s `FlutterEngine` when the `Service` goes from foreground to background.
    `void` | `onMoveToForeground()` | Call this method from the `Service` that is attached to this `ServiceControlSurface`'s `FlutterEngine` when the `Service` goes from background to foreground.

- - ### Method Detail

    - #### attachToService

          void attachToService​(@NonNull
                               Service service,
                               @Nullable
                               androidx.lifecycle.Lifecycle lifecycle,
                               boolean isForeground)

      Call this method from the `Service` that is running the `FlutterEngine` that is associated with this `ServiceControlSurface`.

      Once a `Service` is created, and its associated `FlutterEngine` is executing Dart code, the `Service` should invoke this method. At that point the `FlutterEngine` is considered "attached" to the `Service` and all `ServiceAware` plugins are given access to the `Service`.

      `isForeground` should be true if the given `Service` is running in the foreground, false otherwise.

    - #### detachFromService

          void detachFromService()

      Call this method from the `Service` that is attached to this `ServiceControlSurfaces`'s `FlutterEngine` when the `Service` is about to be destroyed.

      This method gives each `ServiceAware` plugin an opportunity to clean up its references before the `is destroyed`.

    - #### onMoveToForeground

          void onMoveToForeground()

      Call this method from the `Service` that is attached to this `ServiceControlSurface`'s `FlutterEngine` when the `Service` goes from background to foreground.

    - #### onMoveToBackground

          void onMoveToBackground()

      Call this method from the `Service` that is attached to this `ServiceControlSurface`'s `FlutterEngine` when the `Service` goes from foreground to background.