启动模拟器或者连接手机,通过adb命令的方式获取App冷启动、热启动时间。
启动App的adb命令:
adb shell am start -W packagename/绝对路径下的MainActivity
-W:启动完成之后,返回启动耗时。
比如,我的packagename是com.example.myapplication,我的MainActivity的配置如下:
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.MyApplication">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
则adb启动命令为
adb shell am start -W com.example.myapplication/com.example.myapplication.MainActivity
一、冷启动时间(如果应用启动过,则从最近任务杀进程,再使用上面的命令启动):文章来源:https://www.toymoban.com/news/detail-745492.html
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.myapplication/.MainActivity }
Status: ok
LaunchState: COLD
Activity: com.example.myapplication/.MainActivity
TotalTime: 1885
WaitTime: 1887
Complete
二、热启动时间(App退出到后台,但不杀进程):文章来源地址https://www.toymoban.com/news/detail-745492.html
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 front
Status: ok
LaunchState: HOT
Activity: com.example.myapplication/.MainActivity
TotalTime: 79
WaitTime: 82
Complete
到了这里,关于Android获取App冷启动、热启动时间的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!