前面已经分析完了Flutter程序初始化的的过程,当FlutterView创建完成之后,Engine已经准备好了。这个时候FlutterView被设置到Activity上,并且增加了对应的LaunchView。然后偶FlutterActivityDelegate会开始执行Flutter程序。

 public void onCreate(Bundle savedInstanceState) {
    
        String[] args = getArgsFromIntent(activity.getIntent());
        FlutterMain.ensureInitializationComplete(activity.getApplicationContext(), args);

        flutterView = viewFactory.createFlutterView(activity);
        if (flutterView == null) {
            FlutterNativeView nativeView = viewFactory.createFlutterNativeView();
            flutterView = new FlutterView(activity, null, nativeView);
            flutterView.setLayoutParams(matchParent);
            activity.setContentView(flutterView);
            launchView = createLaunchView();
            if (launchView != null) {
                addLaunchView();
            }
        }

        if (loadIntent(activity.getIntent())) {
            return;
        }

        String appBundlePath = FlutterMain.findAppBundlePath(activity.getApplicationContext());
        if (appBundlePath != null) {
            runBundle(appBundlePath);
        }
    }

前面我们已经分析过了runBundle方法在Java层的实现,最终调用了FlutterJNI的方法:

继续阅读

0