Java – Track user sessions on Android applications

Track user sessions on Android applications… here is a solution to the problem.

Track user sessions on Android applications

I’m trying to track how much time a user spends in a day on my app and send this data to my server. I was wondering if google analytic could do the job for me, I’ve searched for this and here I come know google analytic can measure screen views that allow you to see what users view the most, and how they navigate between different content.
I guess Google Analytics does session tracking? (I haven’t found this yet).
If google analytic doesn’t do the work, can you suggest how I can do it manually, I just need a rough sketch.

Solution

Create your own CustomApplication class and have it extend the Application, then override the onCreate method, which will be called to open when your application is called, where you can send the start time of the session to your server. Then override the onDestroy method, which will be called when the application shuts down, and send the end time of the session to your server there.

Use the ID to match the correct start time to the correct end time. Then on your server, you can easily calculate the difference between end time and start time to determine how long users have spent on your app. You can then simply add up all the session times of a day to get the total time users spend on your app on a specific day.

Related Problems and Solutions