2

Is it possible to make a service running in backgroud to be notified when an arbritary activity/application is started and ended by a user? I want to use it to log how often and for how long different applications are used in Android.

Justin Johnson
  • 30,978
  • 7
  • 65
  • 89
qtips
  • 625
  • 6
  • 17

2 Answers2

0

As stated in question & answer posted bellow:

There is no solution other than periodically read a list of processes and detecting foreground process. You need a service for this. Unfortunately, Android does not provide means such as broadcast events for foreground process change.

App to monitor other apps on android and the reply which contains interesting and usefull suggestion and some sample code.

Community
  • 1
  • 1
FanaticD
  • 1,416
  • 4
  • 20
  • 36
0

Have a look at ActivityManager.getRunningTasks(). Unfortunately you would need to be running continuously to see tasks starting and stopping. I'm not aware of any event you can listen for.

Philip Pearl
  • 1,523
  • 16
  • 26