Class FlutterEngineGroup
- java.lang.Object
-
- io.flutter.embedding.engine.FlutterEngineGroup
-
public class FlutterEngineGroup extends Object
Represents a collection ofFlutterEngines who share resources to allow them to be created faster and with less memory than calling theFlutterEngine's constructor multiple times.When creating or recreating the first
FlutterEnginein the FlutterEngineGroup, the behavior is the same as creating aFlutterEnginevia its constructor. When subsequentFlutterEngines are created, resources from an existing livingFlutterEngineis re-used.The shared resources are kept until the last surviving
FlutterEngineis destroyed.Deleting a FlutterEngineGroup doesn't invalidate its existing
FlutterEngines, but it eliminates the possibility to create moreFlutterEngines in that group.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFlutterEngineGroup.OptionsOptions 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 FlutterEnginecreateAndRunDefaultEngine(Context context)Creates aFlutterEnginein this group and run itsDartExecutorwith a default entrypoint of the "main" function in the "lib/main.dart" file.FlutterEnginecreateAndRunEngine(Context context, DartExecutor.DartEntrypoint dartEntrypoint)Creates aFlutterEnginein this group and run itsDartExecutorwith the specifiedDartExecutor.DartEntrypoint.FlutterEnginecreateAndRunEngine(Context context, DartExecutor.DartEntrypoint dartEntrypoint, String initialRoute)Creates aFlutterEnginein this group and run itsDartExecutorwith the specifiedDartExecutor.DartEntrypointand the specifiedinitialRoute.FlutterEnginecreateAndRunEngine(FlutterEngineGroup.Options options)Creates aFlutterEnginein this group and run itsDartExecutorwith the specifiedDartExecutor.DartEntrypoint, the specifiedinitialRouteand thedartEntrypointArgs.
-
-
-
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. UsedartVmArgsto 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 aFlutterEnginein this group and run itsDartExecutorwith a default entrypoint of the "main" function in the "lib/main.dart" file.If no prior
FlutterEnginewere created in this group, the initialization cost will be slightly higher than subsequent engines. The very firstFlutterEnginecreated 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 aFlutterEnginein this group and run itsDartExecutorwith the specifiedDartExecutor.DartEntrypoint.If no prior
FlutterEnginewere created in this group, the initialization cost will be slightly higher than subsequent engines. The very firstFlutterEnginecreated 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 aFlutterEnginein this group and run itsDartExecutorwith the specifiedDartExecutor.DartEntrypointand the specifiedinitialRoute.If no prior
FlutterEnginewere created in this group, the initialization cost will be slightly higher than subsequent engines. The very firstFlutterEnginecreated 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 aFlutterEnginein this group and run itsDartExecutorwith the specifiedDartExecutor.DartEntrypoint, the specifiedinitialRouteand thedartEntrypointArgs.If no prior
FlutterEnginewere created in this group, the initialization cost will be slightly higher than subsequent engines. The very firstFlutterEnginecreated 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.
-
-