text stringlengths 1 372 |
|---|
@override |
public void onClick(View v) { |
startActivity( |
FlutterActivity |
.withcachedengine("my_engine_id") |
.build(currentactivity) |
); |
} |
}); |
<code_end> |
<code_start> |
myButton.setOnClickListener { |
startActivity( |
FlutterActivity |
.withcachedengine("my_engine_id") |
.build(this) |
) |
} |
<code_end> |
when using the withCachedEngine() factory method, |
pass the same ID that you used when caching the desired |
FlutterEngine. |
now, when you launch FlutterActivity, |
there is significantly less delay in |
the display of flutter content. |
info note |
when using a cached FlutterEngine, that FlutterEngine outlives any |
FlutterActivity or FlutterFragment that displays it. keep in |
mind that dart code begins executing as soon as you pre-warm the |
FlutterEngine, and continues executing after the destruction of your |
FlutterActivity/FlutterFragment. to stop executing and clear resources, |
obtain your FlutterEngine from the FlutterEngineCache and destroy the |
FlutterEngine with FlutterEngine.destroy(). |
info note |
runtime performance isn’t the only reason that you might |
pre-warm and cache a FlutterEngine. |
a pre-warmed FlutterEngine executes dart code independent |
from a FlutterActivity, which allows such a FlutterEngine |
to be used to execute arbitrary dart code at any moment. |
Non-UI application logic can be executed in a FlutterEngine, |
like networking and data caching, and in background behavior |
within a service or elsewhere. when using a FlutterEngine |
to execute behavior in the background, be sure to adhere to all |
android restrictions on background execution. |
info note |
flutter’s debug/release builds have drastically different |
performance characteristics. to evaluate the performance |
of flutter, use a release build. |
<topic_end> |
<topic_start> |
initial route with a cached engine |
the concept of an initial route is available when configuring a |
FlutterActivity or a FlutterFragment with a new FlutterEngine. |
however, FlutterActivity and FlutterFragment don’t offer the |
concept of an initial route when using a cached engine. |
this is because a cached engine is expected to already be |
running dart code, which means it’s too late to configure the |
initial route. |
developers that would like their cached engine to begin |
with a custom initial route can configure their cached |
FlutterEngine to use a custom initial route just before |
executing the dart entrypoint. the following example |
demonstrates the use of an initial route with a cached engine: |
<code_start> |
public class MyApplication extends application { |
@override |
public void onCreate() { |
super.onCreate(); |
// instantiate a FlutterEngine. |
flutterEngine = new FlutterEngine(this); |
// configure an initial route. |
flutterEngine.getNavigationChannel().setInitialRoute("your/route/here"); |
// start executing dart code to pre-warm the FlutterEngine. |
flutterEngine.getDartExecutor().executeDartEntrypoint( |
DartEntrypoint.createDefault() |
); |
// cache the FlutterEngine to be used by FlutterActivity or FlutterFragment. |
FlutterEngineCache |
.getinstance() |
.put("my_engine_id", flutterEngine); |
} |
} |
<code_end> |
<code_start> |
class MyApplication : application() { |
lateinit var flutterEngine : FlutterEngine |
override fun onCreate() { |
super.onCreate() |
// instantiate a FlutterEngine. |
flutterEngine = FlutterEngine(this) |
// configure an initial route. |
flutterEngine.navigationChannel.setInitialRoute("your/route/here"); |
// start executing dart code to pre-warm the FlutterEngine. |
flutterEngine.dartExecutor.executeDartEntrypoint( |
DartExecutor.DartEntrypoint.createDefault() |
) |
// cache the FlutterEngine to be used by FlutterActivity or FlutterFragment. |
FlutterEngineCache |
.getinstance() |
.put("my_engine_id", flutterEngine) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.