android-discuss icon indicating copy to clipboard operation
android-discuss copied to clipboard

[问答]如何正确统计每个界面启动时间?

Open czn6 opened this issue 10 years ago • 6 comments

如何正确统计每个界面启动时间? onCreate-onResume 两个方法的时间差?

czn6 avatar Dec 28 '15 08:12 czn6

启动这个页面的地方开始计时,onResume结束停止计时?

halfcupCn avatar Dec 28 '15 13:12 halfcupCn

@haflcup 感谢回复 不知道有没有更好的方法

czn6 avatar Dec 29 '15 04:12 czn6

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 ,发布阶段要看做这个统计的目的是什么。

以上仅为个人理解,可能有误,感谢指正。

johnwatsondev avatar Dec 31 '15 08:12 johnwatsondev

onCreate() , 开始计时 onCreate(),使用某一个View,View.post(Runnable) -> run() ,停止计时 这个时间大概就是当前Activity/Fragment从创建到显示花费的时间了 要统计每一个当然是用基类/父类了

aWangVest avatar Jan 11 '16 16:01 aWangVest

统计每一个界面使用时间怎么搞?

meicuihui avatar Sep 05 '17 02:09 meicuihui

创建页面的时候获取一个时间,退出的时候获取一个时间,计算

PellingLyu avatar Sep 05 '17 04:09 PellingLyu