Package io.flutter.embedding.engine.plugins.activity

# Interface ActivityAware

public interface ActivityAware
`FlutterPlugin` that is interested in `Activity` lifecycle events related to a `FlutterEngine` running within the given `Activity`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `onAttachedToActivity(ActivityPluginBinding binding)`
  This `ActivityAware` `FlutterPlugin` is now associated with an `Activity`.
  `void`
  `onDetachedFromActivity()`
  This plugin has been detached from an `Activity`.
  `void`
  `onDetachedFromActivityForConfigChanges()`
  The `Activity` that was attached and made available in `onAttachedToActivity(ActivityPluginBinding)` has been detached from this `ActivityAware`'s `FlutterEngine` for the purpose of processing a configuration change.
  `void`
  `onReattachedToActivityForConfigChanges(ActivityPluginBinding binding)`
  This plugin and its `FlutterEngine` have been re-attached to an `Activity` after the `Activity` was recreated to handle configuration changes.

- ## Method Details

  - ### onAttachedToActivity

    void onAttachedToActivity(@NonNull ActivityPluginBinding binding)
    This `ActivityAware` `FlutterPlugin` is now associated with an `Activity`.

    This method can be invoked in 1 of 2 situations:

    - This `ActivityAware` `FlutterPlugin` was just added to a `FlutterEngine` that was already connected to a running `Activity`.
    - This `ActivityAware` `FlutterPlugin` was already added to a `FlutterEngine` and that `FlutterEngine` was just connected to an `Activity`.
    The given `ActivityPluginBinding` contains `Activity`-related references that an `ActivityAware` `FlutterPlugin` may require, such as a reference to the actual `Activity` in question. The `ActivityPluginBinding` may be referenced until either `onDetachedFromActivityForConfigChanges()` or `onDetachedFromActivity()` is invoked. At the conclusion of either of those methods, the binding is no longer valid. Clear any references to the binding or its resources, and do not invoke any further methods on the binding or its resources.

  - ### onDetachedFromActivityForConfigChanges

    void onDetachedFromActivityForConfigChanges()
    The `Activity` that was attached and made available in `onAttachedToActivity(ActivityPluginBinding)` has been detached from this `ActivityAware`'s `FlutterEngine` for the purpose of processing a configuration change.

    By the end of this method, the `Activity` that was made available in `onAttachedToActivity(ActivityPluginBinding)` is no longer valid. Any references to the associated `Activity` or `ActivityPluginBinding` should be cleared.

    This method should be quickly followed by `onReattachedToActivityForConfigChanges(ActivityPluginBinding)`, which signifies that a new `Activity` has been created with the new configuration options. That method provides a new `ActivityPluginBinding`, which references the newly created and associated `Activity`.

    Any `Lifecycle` listeners that were registered in `onAttachedToActivity(ActivityPluginBinding)` should be deregistered here to avoid a possible memory leak and other side effects.

  - ### onReattachedToActivityForConfigChanges

    void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding)
    This plugin and its `FlutterEngine` have been re-attached to an `Activity` after the `Activity` was recreated to handle configuration changes.

    `binding` includes a reference to the new instance of the `Activity`. `binding` and its references may be cached and used from now until either `onDetachedFromActivityForConfigChanges()` or `onDetachedFromActivity()` is invoked. At the conclusion of either of those methods, the binding is no longer valid. Clear any references to the binding or its resources, and do not invoke any further methods on the binding or its resources.

  - ### onDetachedFromActivity

    void onDetachedFromActivity()
    This plugin has been detached from an `Activity`.

    Detachment can occur for a number of reasons.

    - The app is no longer visible and the `Activity` instance has been destroyed.
    - The `FlutterEngine` that this plugin is connected to has been detached from its `FlutterView`.
    - This `ActivityAware` plugin has been removed from its `FlutterEngine`.
    By the end of this method, the `Activity` that was made available in `onAttachedToActivity(ActivityPluginBinding)` is no longer valid. Any references to the associated `Activity` or `ActivityPluginBinding` should be cleared.

    Any `Lifecycle` listeners that were registered in `onAttachedToActivity(ActivityPluginBinding)` or `onReattachedToActivityForConfigChanges(ActivityPluginBinding)` should be deregistered here to avoid a possible memory leak and other side effects.