时间的应用程序正在运行 [英] Time that an application is running

查看:123
本文介绍了时间的应用程序正在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定多长时间的应用程序已运行?是否有广播的应用程序,每次启动时间和关机?

How do I determine how long an application has been running? Is there a broadcast each time an app is launched and shutdown?

我试图登录使用的应用程序所花费的时间。

I am trying to log the time spent using an application.

推荐答案

如果您有兴趣在登录自己的应用程序的使用,您可以使用 System.currentTimeMillis的()来得到的开始时间,并且当应用程序被关闭用值差异比较它返回

If you are interested in logging your own application's use, you can use System.currentTimeMillis() to get the start time, and diff it with the value returned when the app is closed.

要得到整个时间的应用程序是,你会想与的onCreate()的onDestroy()你的最重要的活动类。对于刚刚在时间的应用程序是在前台,使用 onResume()的onPause()在您的每一个活动的类和每个班级总结的时间。

To get the entire time the app is up, you would want to diff between onCreate() and onDestroy() of your foremost Activity class. For just the time the app is in the foreground, use onResume() and onPause() in each of your Activity classes and sum the time from each class.

这篇关于时间的应用程序正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆