Android app启动节点与上报启动的方法

发布时间:2022-04-29 10:11:49 作者:iii
来源:亿速云 阅读:115

本文小编为大家详细介绍“Android app启动节点与上报启动的方法”,内容详细,步骤清晰,细节处理妥当,希望这篇“Android app启动节点与上报启动的方法”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

app启动的关键节点

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

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

精髓在这张图里:

Android app启动节点与上报启动的方法

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

推荐用contentprovider,设置initOrder.

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

Android app启动节点与上报启动的方法

启动时间怎么算

方案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

    <provider
            android:name="com.google.firebase.perf.provider.FirebasePerfProvider"
            android:authorities="${applicationId}.firebaseperfprovider"
            android:exported="false"
            android:initOrder="101" />

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

Android app启动节点与上报启动的方法

<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全类名

在控制台会输出日志:

Android app启动节点与上报启动的方法

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

读到这里,这篇“Android app启动节点与上报启动的方法”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. 启动hadoop的节点
  2. android Theme启动APP闪屏处理

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android app

上一篇:Python怎么使用Tkinter GUI实现输入验证功能

下一篇:Java中的volatile关键字有什么用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》