[英]time the app took while running
I want to calculate the time an app took while running in the foreground activity, 我想计算应用程序在前台活动中运行所花费的时间,
for example : if I opened my fb application on android, can I know the time I opened it and the time I closed the application at it or no? 例如:如果我在android上打开了fb应用程序,是否可以知道我打开它的时间以及关闭它的时间?
I want to know the time of a running app in the front not the background services. 我想知道前端运行应用程序的时间,而不是后台服务的时间。
Thanks. 谢谢。
This is unfortunately a little difficult to do in Android. 不幸的是,这在Android中有点困难。 Generally, this is the idea:
通常,这是一个主意:
What I do in my app is the following: 我在应用程序中执行的操作如下:
openArray
and closeArray
openArray
和closeArray
getCurrentTimeMillis
is pushed onto openArray
getCurrentTimeMillis
都会推送到openArray
getCurrentTimeMillis
is pushed onto closeArray
getCurrentTimeMillis
都会推送到closeArray
openArray
and closeArray
have the same number of elements, that means the app has been closed. openArray
和closeArray
的元素数相同,就意味着该应用程序已关闭。 Subtract the first element of openArray
from the last element of closeArray
. openArray
从最后一个元素closeArray
。 That should give you the number of milliseconds the application was open in front of the user. Sorry for the longish answer. 对不起,我的回答太长了。 Let me know if this makes any sense.
让我知道这是否有意义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.