Changed the behavior of the client session to reflect the more modern approach adopted by mobile trackers.
Instead of background thread that updates the session in regular intervals, the session info is now updated on each tracked event. It checks for timeouts since last tracked event and starts a new session if necessary.
In addition to checking for session updates when new events are tracked, I also added a check for session updates in the set_is_background() function. This ensures that transitions between background states are handled with the correct timeout and not ignored.
Session information is persisted in a SQLite database as before. However, instead of saving to the database in the background thread, changes are persisted when session context is fetched and updated. This might have a small toll on the time it takes to track an event. However, since session updates are relatively rare (only after timeouts), I thought it's not a problem.
Changed the behavior of the client session to reflect the more modern approach adopted by mobile trackers.
Instead of background thread that updates the session in regular intervals, the session info is now updated on each tracked event. It checks for timeouts since last tracked event and starts a new session if necessary.
In addition to checking for session updates when new events are tracked, I also added a check for session updates in the
set_is_background()
function. This ensures that transitions between background states are handled with the correct timeout and not ignored.Session information is persisted in a SQLite database as before. However, instead of saving to the database in the background thread, changes are persisted when session context is fetched and updated. This might have a small toll on the time it takes to track an event. However, since session updates are relatively rare (only after timeouts), I thought it's not a problem.