javaandroidandroid-serviceandroid-gpsgoogle-location-services

Is Google location services a service - that runs in background


I want my app to get updates of the current location, and act upon it. I am planning on creating a service, that will host the Google API client code and location update code.

The name though throws me off: Is google location SERVICES a service that will automatically run in the background, like the service I was to create? Or is it just a name and I should go ahead with my plan?


Solution

  • You're not thinking about this correctly - it doesn't matter how Google implemented it. To directly answer your question, I can say with near certainty that it's not called "services" because it's a Service - the two have nothing to do with each other. Google likely uses a whole series of Service's, but you don't have to care about that.

    All that you need to know is that it works - for as long as you request updates, and obviously the frequency and accuracy will depend on the filters/providers you request, you will continue to get updates. You do not need to maintain a Service in the background to continue to receive updates. You only need to maintain a Service if you need to receive and continually do something with those updates while your app is in the background.

    I will also say that this can come as a disadvantage. If you request location updates and never make the api call to stop receiving updates, you will cause your app to hold a partial wakelock on the system, and you'll kill your users' batteries. Once you've got the location info you need, make the proper call to stop receiving updates.

    Think about what you need location for, how often you need it, etc, and know that Google location services will continue to call your callback object as long as it hasn't been garbage collected.