Click here to Skip to main content
15,887,928 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Problem at Hand:
I have to create a Service 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 the game is opened and run? 2. For how much time the each game has run.

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:

Game Number of times the game is run Duration of Game play

Game 1 20 times played for 15 hours in total

Game 2 16 times played for 25 hours in total

..

..

Game 5 10 times played for 12 hours in total

Possible Approach:

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.

So say if application is brought to memory at 9:00 pm and exits to background at 9:30 pm that gives us a game play 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 a 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.

Coding:
I have no idea about Service 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 other 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.
Posted
Comments
Ganesh KP 6-Dec-13 4:12am    
sounds interesting, you can do it using background services in android, you can trigger that service when ever particular app is invoked like you can invoke your app when there is a incoming call or like that. You can calculate the start time and end time of the app when your games starts and can save either in local database or can update to server database via some webservices.

looks like you have a good techie brain. you need to separate the kind of operations that you have to perform in your app like

1. You have to write a background service
2. You have to invoke your app when ever a particular app in your mobile is invoked and do certain operations like get the app id, and start time and end time and using your service you have to update either local database or server via webserivces.

hope you understands what I mean to say, if not then comment here below.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900