title: How to create a Service which continuously monitors app usage information?
body: <p><strong>Problem at Hand</strong>:
  I have to create a <code>Service</code> which runs continuously. This service monitors 5 apps say 5 android games installed on your phone. This service needs to get the information of:
   1. How many times is the game opened and run? 
   2. For how much time each game has run. </p>
  
  <p>for example: Say If I have this service installed in my app. And I let it run for a month. I need information of this kind on the screen of the app:</p>
  
  <p><strong>Game</strong>     <strong>Number of times the game is run</strong>     <strong>Duration of Game play</strong></p>
  
  <p>Game 1                     20 times played for                         15 hours in total</p>
  
  <p>Game 2                     16 times played for                       25 hours in total</p>
  
  <p>..</p>
  
  <p>..</p>
  
  <p>Game 5                   10 times played for                       12 hours in total</p>
  
  <p><strong>Possible Approach</strong>:
  When an application loads it comes in the memory. Noting the system clocks time while the application starts. And when the application ends or is put in the background noting the time again.</p>
  
  <p>So say if an application is brought to memory at 9:00 pm and exits to background at 9:30 pm that gives us a gameplay time of 30 mins. Next time the application is played the duration will be added to 30 from the previous play stored in some sort of variable and so on. 
  Each time an application is brought into the memory the counter of it being played should increase by one. Hence giving us the number of times an application is played.</p>
  
  <p><strong>Coding:</strong>
  I have no idea about <code>Service</code> in Android as I have never really worked on them. Any tutorials related to my problem at hand will be very helpful.
  Secondly, if there is another way in which this could be done. I would like to know that as well. I could really use some code snippet for me to start this project.</p>