Search code examples
androidandroid-service

Android - Timer and GPS tracking. Should I use a service?


I am writing and app that has a running timer (updates the UI every 10th of a second like a watch) and also tracks distance via GPS. The intended use case is to have this app run for up to a couple of hours, so it shouldn't ever be killed by the system. Very similar to many of the running applications that you find on the market today (although that isn't what I am making).

That requirement that it should not be killed by the system points me to creating a service, but it seems like communicating the timer and distance updates to the UI that often would be really inefficient.

Would using a service be the best approach here? If so, how do I efficiently handle updating the time and distance on the UI? Or is there another way to keep the system from killing my app?


Solution

  • I have decided that I will indeed use a service, but only start it up and use it when the activity is paused. The Activity will pass the current state to the service where it will take care of all everything that needs to be done, and when resumed the activity will get the state back from the service and kill it off.