app启动的关键节点
经常利用content provider 和Androidx里的 startup库来对库进行初始化操作,那么app启动关键方法的执行顺序是什么样的呢? 怎么样控制我的库的启动顺序APP?
参考这篇文章: Android工商银行电话人工客服 多个 ContentProvGoogleidegoogleplayr 初始化顺序
精髓在这张图里:

回答上面的问题: 怎么样控制我的库的启动顺序?
推荐用contentprovider,设置initOrder.
不推荐用startup,因为它只能在degoogle浏览器pendices()回调里通过依赖来控制,是强依赖,不够灵活

启动时间怎么算
方案1: 参考firebase:
从第一个contentProvider的attachInfo,到第一个页面的onReusme:
app-start-applicationforeground-background-traces
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的配置:
initOrdegoogleplay安卓版下载r=”appetite101″,基本是最大的. 项目枸杞里其他的Provider都application没有怎么配置initOrder
<provider
android:name="com.google.firebase.perf.provider.FirebasePerfProvider"
android:authorities="${applicationId}.firebaseperfprovider"
android:exported="false"
android:initOrder="101" />
可以自己搞个类似的trace打印/上报一下

<provider
android:name="com.xxx.logs.AppStartMeasurer"
android:authorities="${applicationId}.AppStartMeasurer"
android:exported="false"
android:initOrder="102" />
然后就可以看logcat的日志输出+ trace平台的统计了
方案2 : ams
adb 命令:
adb shell am start -W 包名/入口activity全类名
在控制台会输出日志:

这里的时间会比方案1统计到的时间小一些
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)