Flutter&Android 启动页(闪屏页)的加载流程和优化方案(1),Android内存泄漏总结

本文详细解析了Flutter和Android应用的启动页(闪屏页)加载流程,包括FlutterActivity的onCreate方法、FlutterSurfaceView和FlutterView的创建。讨论了如何通过使用原生Surface显示启动页和在子线程中加载,以优化启动性能,同时提供了SVGA动画的实现案例。文章结尾强调了基础和深度学习的重要性。
摘要由CSDN通过智能技术生成

@Override

protected void onCreate(@Nullable Bundle savedInstanceState) {

switchLaunchThemeForNormalTheme();

super.onCreate(savedInstanceState);

lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);

delegate = new FlutterActivityAndFragmentDelegate(this);

///创建绑定引擎等

delegate.onAttach(this);

///用于插件、框架恢复状态

delegate.onActivityCreated(savedInstanceState);

///设置窗口背景透明,隐藏 status bar

configureWindowForTransparency();

///这里是咱们的入口

setContentView(createFlutterView());

configureStatusBarForFullscreenFlutterExperience();

}

setContentView大家很熟悉,我们直接看createFlutterView() 这个方法:

@NonNull

private View createFlutterView() {

return delegate.onCreateView(

null /* inflater /, null / container /, null / savedInstanceState */);

}

FlutterActivityAndFragmentDelegate


flutter的初始化、启动等操作都是委托给它的。

我们继续看onCreateView,我将说明以注释的形式写在代码里

@NonNull

View onCreateView(

LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

Log.v(TAG, “Creating FlutterView.”);

ensureAlive();

if (host.getRenderMode() == RenderMode.surface) {

/// flutter 应用在surface上显示,所以会进入到这里

FlutterSurfaceView flutterSurfaceView =

new FlutterSurfaceView(

host.getActivity(), host.getTransparencyMode() == TransparencyMode.transparent);

// Allow our host to customize FlutterSurfaceView, if desired.

host.onFlutterSurfaceViewCreated(flutterSurfaceView);

// Create the FlutterView that owns the FlutterSurfaceView.

///用我们的flutterSurfaceView 初始化了一个 FlutterView

flutterView = new FlutterView(host.getActivity(), flutterSurfaceView);

} else {

FlutterTextureView flutterTextureView = new FlutterTextureView(host.getActivity());

// Allow our host to customize FlutterSurfaceView, if desired.

host.onFlutterTextureViewCreated(flutterTextureView);

// Create the FlutterView that owns the FlutterTextureView.

flutterView = new FlutterView(host.getActivity(), flutterTextureView);

}

// Add listener to be notified when Flutter renders its first frame.

flutterView.addOnFirstFrameRenderedListener(flutterUiDisplayListener);

/// 创建一个闪屏view - FlutterSplashView

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值