I need to track app usage in Android like how AppUsage does it (i.e. track the number of app launches, and time spent using each). What I plan on doing is recording the start time when an app is launched, and then getting the end time when an app is paused or stopped. In LogCat, I'm able to see logs of Activity starting. I've looked at the available system broadcasts, I'm not sure if there is anything that broadcasts whenever an activity is started. Basically, how do I detect when an activity is launched?
Edit:
Moreover, Android also has a usage statistics system available internally which can be found in the Spare Parts app or when *#*#4636#*#*
is dialed (Testing -> Usage statistics)
We can now access app usage history on an Android device with the new android.app.usage API released as part of Android 5.0 APIs.The system collects the usage data on a per-app basis, aggregating the data over daily, weekly, monthly, and yearly intervals
For each app, the system records the following data:
Timestamp capturing when a component (identified by a package and activity name) moved to the foreground or background during a day
Timestamp capturing when a device configuration changed (such as when the device orientation changed because of rotation)
Refr : http://developer.android.com/reference/android/app/usage/package-summary.html