Flutter——在Android平台上的启动流程浅析

}

很简单,继续往里走

public static void startInitialization(@NonNull Context applicationContext) {

if (isRunningInRobolectricTest) {

return;

}

FlutterLoader.getInstance().startInitialization(applicationContext);

}

上面的方法用于初始化 native system(即C++),并最终会调用下面的方法:

我将说明以注释的形式写在下面

public void startInitialization(@NonNull Context applicationContext, @NonNull Settings settings) {

if (this.settings != null) {

return;

}

///确保运行在 主线程

if (Looper.myLooper() != Looper.getMainLooper()) {

throw new IllegalStateException(“startInitialization must be called on the main thread”);

}

// Ensure that the context is actually the application context.

final Context appContext = applicationContext.getApplicationContext();

this.settings = settings;

initStartTimestampMillis = SystemClock.uptimeMillis();

///配置 aotSharedLibraryName、flutterAssetsDir、

/// vmSnapshotData、isolateSnapshotData

///等参数

initConfig(appContext);

///初始化VsyncWaiter,并设置回调

/// 当vsync信号到来时,就调用我们设置的回调,最终会触发页面的刷新

VsyncWaiter.getInstance((WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE))

.init();

// 子线程

///这里主要是抽取资源文件,

///加载 flutter(libflutter.so)代码

Callable initTask =

new Callable() {

@Override

public InitResult call() {

ResourceExtractor resourceExtractor = initResources(appContext);

System.loadLibrary(“flutter”);

// Prefetch the default font manager as soon as possible on a background thread.

// It helps to reduce time cost of engine setup that blocks the platform thread.

Executors.newSingleThreadExecuto

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值