I'm working on an application where, once the user starts driving, I need to periodically check their activity every 2.5 minutes (150 seconds) to determine whether they are still driving, walking, or have stopped. If they are still driving, I want to keep rescheduling the task until the user is no longer in a driving state.
Currently, I'm using startMonitoringSignificantLocationChanges to wake the app when the user's location changes, which works as expected. However, the activity detection stops after the first result is received, and I can't continue tracking the user's activity in the background (or after the app is killed from the app switcher).
Here's my approach:
- After receiving a significant location change, I start tracking the user’s activity to check if they are driving or have stopped.
- I reschedule this task every 2.5 minutes as long as the user remains in a driving state.
- I need this process to run even when the app is in the background or terminated by the user.
Question: Is it possible to keep activity detection running periodically after receiving a location change, even when the app is in the background or terminated? What is the recommended way to implement this?
I would appreciate any suggestions or best practices for achieving this functionality.