I am currently researching how to track user activity time within an application. While attempting to implement this in Flutter, I encountered some issues which I will outline below. If you have any solutions or alternative approaches for this task, please let me know.
I tried tracking user activity time using Flutter’s lifecycle states. However, I encountered a problem: when the app is moved to the background and then killed or removed from recent tabs, no state or activity methods are invoked.
To address this, I implemented the tracking on the native Android side, as the onDestroy method is called in every case when the app is killed. I then tried to integrate this with Flutter using a method channel. While the onDestroy method is invoked on the native side and logs are recorded, the Flutter activity is destroyed before the Flutter code can be executed.
The goal is to avoid frequent time checks and instead simply record the start time, end time, pause time, and resume time, from which the total usage time can be calculated.
If anyone has a solution for this issue or can provide guidance on how to achieve this, please let me know.
I just expecting that i got the time duration of a user that he/she used the application for this time duration.
Vasani Viraj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.