我正在将FlutterActivity
集成到原生Android应用程序中。 我有CustomFlutterActivity
继承自FlutterActivity
,我想使用缓存FlutterEngine
启动它。
这是文档中有关如何执行此操作的代码:
startActivity(
FlutterActivity
.withNewEngine()
.build(currentActivity)
);
我想要实现的是使用缓存引擎启动我的CustomFlutterActivity
(而不是文档所说的通用FlutterActivity
(
在您的CustomFlutterActivity
中,我想这是从FlutterActivity
派生的,您可以覆盖getCachedEngineId
并根据文档提供您之前缓存的my_engine_id
,即:
FlutterEngineCache
.getInstance()
.put("my_engine_id", flutterEngine);
因此:
class CustomFlutterActivity: FlutterActivity() {
override fun getCachedEngineId(): String? {
return "my_engine_id"
}
}
查看文档
您可以覆盖provideFlutterEngine
并从缓存中返回FlutterEngine
。
class CustomFlutterActivity : FlutterActivity() {
override fun provideFlutterEngine(context: Context): FlutterEngine? {
return FlutterEngineCache.getInstance().get("flutter_engine")
}
}