热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Android app启动节点与上报启动实例详解

系统的启动过程非常复杂,下面这篇文章主要给大家介绍了关于Android app启动节点与上报启动的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下

app启动的关键节点

经常利用content provider 和Androidx里的 startup库来对库进行初始化操作,那么app启动关键方法的执行顺序是什么样的呢? 怎么样控制我的库的启动顺序?

参考这篇文章: Android 多个 ContentProvider 初始化顺序

精髓在这张图里:

回答上面的问题: 怎么样控制我的库的启动顺序?

推荐用contentprovider,设置initOrder.

不推荐用startup,因为它只能在dependices()回调里通过依赖来控制,是强依赖,不够灵活

启动时间怎么算

方案1: 参考firebase:

从第一个contentProvider的attachInfo,到第一个页面的onReusme:

app-start-foreground-background-traces:https://firebase.google.com/docs/perf-mon/app-start-foreground-background-traces?authuser=0&platform=android

App start trace
This trace measures the time between when the user opens the app and when the app is responsive. In the console, the trace's name is _app_start. The collected metric for this trace is "duration".

Starts when the app's FirebasePerfProvider ContentProvider completes its onCreate method.

Stops when the first activity's onResume() method is called.

Note that if the app was not cold-started by an activity (for example, by a service or broadcast receiver), no trace is generated.

看一下FirebasePerfProvider的配置:

initOrder="101",基本是最大的. 项目里其他的Provider都没有怎么配置initOrder

    

可以自己搞个类似的trace打印/上报一下

然后就可以看logcat的日志输出+ trace平台的统计了

方案2 : ams

adb 命令:

adb shell am start -W 包名/入口activity全类名

在控制台会输出日志:

这里的时间会比方案1统计到的时间小一些

总结

到此这篇关于Android app启动节点与上报启动的文章就介绍到这了,更多相关Android app启动节点内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!


推荐阅读
author-avatar
mobiledu2502928897
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有