網站首頁 編程語言 正文
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
<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統計到的時間小一些
總結
原文鏈接:https://juejin.cn/post/7091264056123719688
相關推薦
- 2022-10-15 使用Pycharm創建一個Django項目的超詳細圖文教程_python
- 2022-10-08 ASP.NET泛型三之使用協變和逆變實現類型轉換_實用技巧
- 2022-12-07 C++成員函數后面加override問題_C 語言
- 2022-04-09 SpringBoot自定義Validated枚舉校驗器
- 2023-11-11 ValueError: (‘Unrecognized keyword arguments:‘, di
- 2023-12-02 vscode無法連接寶塔ftp排雷
- 2022-03-20 C++?Qt繪制時鐘界面_C 語言
- 2022-11-09 docker容器直接退出如何進入容器調試模式_docker
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支