Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Package Functions | Package Attributes | List of all members
io.flutter.embedding.engine.FlutterEngineGroup Class Reference

Classes

class  Options
 

Public Member Functions

 FlutterEngineGroup (@NonNull Context context)
 
 FlutterEngineGroup (@NonNull Context context, @Nullable String[] dartVmArgs)
 
FlutterEngine createAndRunDefaultEngine (@NonNull Context context)
 
FlutterEngine createAndRunEngine ( @NonNull Context context, @Nullable DartEntrypoint dartEntrypoint)
 
FlutterEngine createAndRunEngine ( @NonNull Context context, @Nullable DartEntrypoint dartEntrypoint, @Nullable String initialRoute)
 
FlutterEngine createAndRunEngine (@NonNull Options options)
 

Package Functions

FlutterEngine createEngine (Context context, @NonNull PlatformViewsController platformViewsController, boolean automaticallyRegisterPlugins, boolean waitForRestorationData)
 

Package Attributes

final List< FlutterEngineactiveEngines = new ArrayList<>()
 

Detailed Description

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

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

The shared resources are kept until the last surviving io.flutter.embedding.engine.FlutterEngine is destroyed.

Deleting a FlutterEngineGroup doesn't invalidate its existing io.flutter.embedding.engine.FlutterEngines, but it eliminates the possibility to create more io.flutter.embedding.engine.FlutterEngines in that group.

Definition at line 36 of file FlutterEngineGroup.java.

Constructor & Destructor Documentation

◆ FlutterEngineGroup() [1/2]

io.flutter.embedding.engine.FlutterEngineGroup.FlutterEngineGroup ( @NonNull Context  context)
inline

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.

Definition at line 47 of file FlutterEngineGroup.java.

47 {
48 this(context, null);
49 }

◆ FlutterEngineGroup() [2/2]

io.flutter.embedding.engine.FlutterEngineGroup.FlutterEngineGroup ( @NonNull Context  context,
@Nullable String[]  dartVmArgs 
)
inline

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.

Definition at line 59 of file FlutterEngineGroup.java.

59 {
60 FlutterLoader loader = FlutterInjector.instance().flutterLoader();
61 if (!loader.initialized()) {
62 loader.startInitialization(context.getApplicationContext());
63 loader.ensureInitializationComplete(context.getApplicationContext(), dartVmArgs);
64 }
65 }

Member Function Documentation

◆ createAndRunDefaultEngine()

FlutterEngine io.flutter.embedding.engine.FlutterEngineGroup.createAndRunDefaultEngine ( @NonNull Context  context)
inline

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

If no prior io.flutter.embedding.engine.FlutterEngine were created in this group, the initialization cost will be slightly higher than subsequent engines. The very first io.flutter.embedding.engine.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 io.flutter.embedding.engine.FlutterEngine#destroy()ed, the next engine created will recreate its dependencies.

Definition at line 81 of file FlutterEngineGroup.java.

81 {
82 return createAndRunEngine(context, null);
83 }
FlutterEngine createAndRunEngine( @NonNull Context context, @Nullable DartEntrypoint dartEntrypoint)

◆ createAndRunEngine() [1/3]

FlutterEngine io.flutter.embedding.engine.FlutterEngineGroup.createAndRunEngine ( @NonNull Context  context,
@Nullable DartEntrypoint  dartEntrypoint 
)
inline

Creates a io.flutter.embedding.engine.FlutterEngine in this group and run its io.flutter.embedding.engine.dart.DartExecutor with the specified DartEntrypoint.

If no prior io.flutter.embedding.engine.FlutterEngine were created in this group, the initialization cost will be slightly higher than subsequent engines. The very first io.flutter.embedding.engine.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 io.flutter.embedding.engine.FlutterEngine#destroy()ed, the next engine created will recreate its dependencies.

Definition at line 98 of file FlutterEngineGroup.java.

99 {
100 return createAndRunEngine(context, dartEntrypoint, null);
101 }

◆ createAndRunEngine() [2/3]

FlutterEngine io.flutter.embedding.engine.FlutterEngineGroup.createAndRunEngine ( @NonNull Context  context,
@Nullable DartEntrypoint  dartEntrypoint,
@Nullable String  initialRoute 
)
inline

Creates a io.flutter.embedding.engine.FlutterEngine in this group and run its io.flutter.embedding.engine.dart.DartExecutor with the specified DartEntrypoint and the specified initialRoute.

If no prior io.flutter.embedding.engine.FlutterEngine were created in this group, the initialization cost will be slightly higher than subsequent engines. The very first io.flutter.embedding.engine.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 io.flutter.embedding.engine.FlutterEngine#destroy()ed, the next engine created will recreate its dependencies.

Definition at line 117 of file FlutterEngineGroup.java.

120 {
121 return createAndRunEngine(
122 new Options(context).setDartEntrypoint(dartEntrypoint).setInitialRoute(initialRoute));
123 }

◆ createAndRunEngine() [3/3]

FlutterEngine io.flutter.embedding.engine.FlutterEngineGroup.createAndRunEngine ( @NonNull Options  options)
inline

Creates a io.flutter.embedding.engine.FlutterEngine in this group and run its io.flutter.embedding.engine.dart.DartExecutor with the specified DartEntrypoint, the specified initialRoute and the dartEntrypointArgs.

If no prior io.flutter.embedding.engine.FlutterEngine were created in this group, the initialization cost will be slightly higher than subsequent engines. The very first io.flutter.embedding.engine.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 io.flutter.embedding.engine.FlutterEngine#destroy()ed, the next engine created will recreate its dependencies.

Definition at line 139 of file FlutterEngineGroup.java.

139 {
140 FlutterEngine engine = null;
141
142 Context context = options.getContext();
143 DartEntrypoint dartEntrypoint = options.getDartEntrypoint();
144 String initialRoute = options.getInitialRoute();
145 List<String> dartEntrypointArgs = options.getDartEntrypointArgs();
146 PlatformViewsController platformViewsController = options.getPlatformViewsController();
147 platformViewsController =
148 platformViewsController != null ? platformViewsController : new PlatformViewsController();
149 boolean automaticallyRegisterPlugins = options.getAutomaticallyRegisterPlugins();
150 boolean waitForRestorationData = options.getWaitForRestorationData();
151
152 if (dartEntrypoint == null) {
153 dartEntrypoint = DartEntrypoint.createDefault();
154 }
155
156 if (activeEngines.size() == 0) {
157 engine =
159 context,
160 platformViewsController,
161 automaticallyRegisterPlugins,
162 waitForRestorationData);
163 if (initialRoute != null) {
164 engine.getNavigationChannel().setInitialRoute(initialRoute);
165 }
166 engine.getDartExecutor().executeDartEntrypoint(dartEntrypoint, dartEntrypointArgs);
167 } else {
168 engine =
170 .get(0)
171 .spawn(
172 context,
173 dartEntrypoint,
174 initialRoute,
175 dartEntrypointArgs,
176 platformViewsController,
177 automaticallyRegisterPlugins,
178 waitForRestorationData);
179 }
180
182
183 final FlutterEngine engineToCleanUpOnDestroy = engine;
184 engine.addEngineLifecycleListener(
185 new FlutterEngine.EngineLifecycleListener() {
186
187 @Override
188 public void onPreEngineRestart() {
189 // No-op. Not interested.
190 }
191
192 @Override
193 public void onEngineWillDestroy() {
194 activeEngines.remove(engineToCleanUpOnDestroy);
195 }
196 });
197 return engine;
198 }
const char * options
FlutterEngine createEngine(Context context, @NonNull PlatformViewsController platformViewsController, boolean automaticallyRegisterPlugins, boolean waitForRestorationData)
FlutterEngine engine
Definition: main.cc:68

◆ createEngine()

FlutterEngine io.flutter.embedding.engine.FlutterEngineGroup.createEngine ( Context  context,
@NonNull PlatformViewsController  platformViewsController,
boolean  automaticallyRegisterPlugins,
boolean  waitForRestorationData 
)
inlinepackage

Definition at line 201 of file FlutterEngineGroup.java.

205 {
206 return new FlutterEngine(
207 context, // Context.
208 null, // FlutterLoader.
209 null, // FlutterJNI.
210 platformViewsController, // PlatformViewsController.
211 null, // String[]. The Dart VM has already started, this arguments will have no effect.
212 automaticallyRegisterPlugins, // boolean.
213 waitForRestorationData, // boolean.
214 this);
215 }

Member Data Documentation

◆ activeEngines

final List<FlutterEngine> io.flutter.embedding.engine.FlutterEngineGroup.activeEngines = new ArrayList<>()
package

Definition at line 38 of file FlutterEngineGroup.java.


The documentation for this class was generated from the following file: