Search code examples
androidandroid-gpsbackground-serviceandroid-fusedlocationforeground-service

Separate class or Service for FusedLocationProvider Location updates?


I currently have a class named LocationCheck.

public class SpeedCheck {

Here the location is retrieved every 3 seconds and is ongoing until the user stops it. To start checking for locations, the class is called in the Main Activity:

startLoc = new LocationCheck(this);

What i am wondering is if the code needs to be in a Service class rather than just an ordinary class (like it currently is). It works so far with no issues, but i may be misunderstanding the concept of Services etc and could be unaware of problems it may face over checking over a long period of time (fairly new to Android dev).

I have looked into Background Service for location updates, but with FusedLocationProvider (which i am using) it is only possible to receive several updates over an hour. This would not be helpful as i need an update every 3 seconds.

Any advice would be greatly appreciated.


Solution

  • If you need to keep checking location in background then use service else you can just simply use it in activity. Simply stop the service when you no longer need it because it will consume more battery if left running in background.