[问答]如何正确统计每个界面启动时间?
如何正确统计每个界面启动时间? onCreate-onResume 两个方法的时间差?
启动这个页面的地方开始计时,onResume结束停止计时?
@haflcup 感谢回复 不知道有没有更好的方法
onCreate-onResume
该方法仅仅是该 Activity 已经创建和适合与用户产生交互行为之间的时间间隔。
SDK 解释如下:
onCreate (Bundle savedInstanceState):
Called when the activity is starting. This is where most initialization should go
onResume ():
for your activity to start interacting with the user.
Keep in mind that onResume is not the best indicator that your activity is visible to the user; a system window such as the keyguard may be in front. Use onWindowFocusChanged(boolean) to know for certain that your activity is visible to the user (for example, to resume a game).
根据 onResume() 方法的解释,在 onWindowFocusChanged(boolean hasFocus) 第一次调用并且 hasFocus 为 true 时更合适。
开发阶段用 Traceview ,发布阶段要看做这个统计的目的是什么。
以上仅为个人理解,可能有误,感谢指正。
onCreate() , 开始计时 onCreate(),使用某一个View,View.post(Runnable) -> run() ,停止计时 这个时间大概就是当前Activity/Fragment从创建到显示花费的时间了 要统计每一个当然是用基类/父类了
统计每一个界面使用时间怎么搞?
创建页面的时候获取一个时间,退出的时候获取一个时间,计算