启动模拟器或者连接手机,通过adb命令的方式获取App冷启动、热启动时间。
启动App的adb命令:
adb shell am start -W packagename/绝对路径下的MainActivity
-W:启动完成之后,返回启动耗时。
比如,我的packagename是com.example.myapplication,我的MainActivity的配置如下:
则adb启动命令为
adb shell am start -W com.example.myapplication/com.example.myapplication.MainActivity
一、冷启动时间(如果应用启动过,则从最近任务杀进程,再使用上面的命令启动):
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.myapplication/.MainActivity }Status: okLaunchState: COLDActivity: com.example.myapplication/.MainActivityTotalTime: 1885WaitTime: 1887Complete
二、热启动时间(App退出到后台,但不杀进程):
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.myapplication/.MainActivity }Warning: Activity not started, its current task has been brought to the frontStatus: okLaunchState: HOTActivity: com.example.myapplication/.MainActivityTotalTime: 79WaitTime: 82Complete
来源地址:https://blog.csdn.net/vancevian/article/details/130978037