Get time usage for all applications in android
- Please note - I want the code/logic not any apps
I was trying a lot for some days to get the usage time for all applications in android , but i was not able to get it .I was able to get the list of all application installed in android but was not able to track their individual timings .
Firstly I thought I can use the logic开发者_如何转开发 of getting the start time and end time of each application, but i was not able to do so .So can anybody let me know how to get the start time and end time for each application (based on their UID's).
But my main problem is getting the usage time .So if you have any other logic then please let me know (with some sample code would be must appreciated).
Disclaimer: I haven't really tried it myself :
getElapsedCpuTime()
Returns elapsed milliseconds of the time this process has run.
As for start time and end time. I managed to find that out by stalking the processes every few seconds.
Hint: activityManager.getRunningTasks(Integer.MAX_VALUE);
As far as I know there is no such thing as "start and end time of application" in Android. Every application is kind of bunch of Activity objects and the system can close/restart any of them in any moment. There is even no normal "exit" which the application can perform.
精彩评论