Package io.flutter.embedding.engine

## Class FlutterEngineGroup

- java.lang.Object
- - io.flutter.embedding.engine.FlutterEngineGroup

-     public class FlutterEngineGroup
      extends Object

  Represents a collection of `FlutterEngine`s who share resources to allow them to be created faster and with less memory than calling the `FlutterEngine`'s constructor multiple times.

  When creating or recreating the first `FlutterEngine` in the FlutterEngineGroup, the behavior is the same as creating a `FlutterEngine` via its constructor. When subsequent `FlutterEngine`s are created, resources from an existing living `FlutterEngine` is re-used.

  The shared resources are kept until the last surviving `FlutterEngine` is destroyed.

  Deleting a FlutterEngineGroup doesn't invalidate its existing `FlutterEngine`s, but it eliminates the possibility to create more `FlutterEngine`s in that group.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `FlutterEngineGroup.Options` | Options that control how a FlutterEngine should be created.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `FlutterEngineGroup​(Context context)` | Create a FlutterEngineGroup whose child engines will share resources.
    `FlutterEngineGroup​(Context context, String[] dartVmArgs)` | Create a FlutterEngineGroup whose child engines will share resources.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `FlutterEngine` | `createAndRunDefaultEngine​(Context context)` | Creates a `FlutterEngine` in this group and run its `DartExecutor` with a default entrypoint of the "main" function in the "lib/main.dart" file.
    `FlutterEngine` | `createAndRunEngine​(Context context, DartExecutor.DartEntrypoint dartEntrypoint)` | Creates a `FlutterEngine` in this group and run its `DartExecutor` with the specified `DartExecutor.DartEntrypoint`.
    `FlutterEngine` | `createAndRunEngine​(Context context, DartExecutor.DartEntrypoint dartEntrypoint, String initialRoute)` | Creates a `FlutterEngine` in this group and run its `DartExecutor` with the specified `DartExecutor.DartEntrypoint` and the specified `initialRoute`.
    `FlutterEngine` | `createAndRunEngine​(FlutterEngineGroup.Options options)` | Creates a `FlutterEngine` in this group and run its `DartExecutor` with the specified `DartExecutor.DartEntrypoint`, the specified `initialRoute` and the `dartEntrypointArgs`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### FlutterEngineGroup

          public FlutterEngineGroup​(@NonNull
                                    Context context)

      Create a FlutterEngineGroup whose child engines will share resources.

      Since the FlutterEngineGroup is likely to have a longer lifecycle than any individual Android component, it's more semantically correct to pass in an application context rather than the individual Android component's context to minimize the chances of leaks.

    - #### FlutterEngineGroup

          public FlutterEngineGroup​(@NonNull
                                    Context context,
                                    @Nullable
                                    String[] dartVmArgs)

      Create a FlutterEngineGroup whose child engines will share resources. Use `dartVmArgs` to pass flags to the Dart VM during initialization.

      Since the FlutterEngineGroup is likely to have a longer lifecycle than any individual Android component, it's more semantically correct to pass in an application context rather than the individual Android component's context to minimize the chances of leaks.

  - ### Method Detail

    - #### createAndRunDefaultEngine

          public FlutterEngine createAndRunDefaultEngine​(@NonNull
                                                         Context context)

      Creates a `FlutterEngine` in this group and run its `DartExecutor` with a default entrypoint of the "main" function in the "lib/main.dart" file.

      If no prior `FlutterEngine` were created in this group, the initialization cost will be slightly higher than subsequent engines. The very first `FlutterEngine` created per program, regardless of FlutterEngineGroup, also incurs the Dart VM creation time.

      Subsequent engine creations will share resources with existing engines. However, if all existing engines were `FlutterEngine.destroy()`ed, the next engine created will recreate its dependencies.

    - #### createAndRunEngine

          public FlutterEngine createAndRunEngine​(@NonNull
                                                  Context context,
                                                  @Nullable
                                                  DartExecutor.DartEntrypoint dartEntrypoint)

      Creates a `FlutterEngine` in this group and run its `DartExecutor` with the specified `DartExecutor.DartEntrypoint`.

      If no prior `FlutterEngine` were created in this group, the initialization cost will be slightly higher than subsequent engines. The very first `FlutterEngine` created per program, regardless of FlutterEngineGroup, also incurs the Dart VM creation time.

      Subsequent engine creations will share resources with existing engines. However, if all existing engines were `FlutterEngine.destroy()`ed, the next engine created will recreate its dependencies.

    - #### createAndRunEngine

          public FlutterEngine createAndRunEngine​(@NonNull
                                                  Context context,
                                                  @Nullable
                                                  DartExecutor.DartEntrypoint dartEntrypoint,
                                                  @Nullable
                                                  String initialRoute)

      Creates a `FlutterEngine` in this group and run its `DartExecutor` with the specified `DartExecutor.DartEntrypoint` and the specified `initialRoute`.

      If no prior `FlutterEngine` were created in this group, the initialization cost will be slightly higher than subsequent engines. The very first `FlutterEngine` created per program, regardless of FlutterEngineGroup, also incurs the Dart VM creation time.

      Subsequent engine creations will share resources with existing engines. However, if all existing engines were `FlutterEngine.destroy()`ed, the next engine created will recreate its dependencies.

    - #### createAndRunEngine

          public FlutterEngine createAndRunEngine​(@NonNull
                                                  FlutterEngineGroup.Options options)

      Creates a `FlutterEngine` in this group and run its `DartExecutor` with the specified `DartExecutor.DartEntrypoint`, the specified `initialRoute` and the `dartEntrypointArgs`.

      If no prior `FlutterEngine` were created in this group, the initialization cost will be slightly higher than subsequent engines. The very first `FlutterEngine` created per program, regardless of FlutterEngineGroup, also incurs the Dart VM creation time.

      Subsequent engine creations will share resources with existing engines. However, if all existing engines were `FlutterEngine.destroy()`ed, the next engine created will recreate its dependencies.