Search code examples
androidlistenerlocationmanager

Using several LocationManager requestLocationUpdates(...) for the same provider


I've got a location service running in background of my app with requestLocationUpdates(LocationManager.GPS_PROVIDER, 5*60*1000 , 1, this) to get a location update every 5 min. In one given activity I need much more frequent updates. Can I create another LocationManager and register another requestLocationUpdates listener for the same provider in this activity as shown below?

locManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 1, this); 

I've tried and it seems to work, but I'd like to be sure that it won't create any conflict with the background service...


Solution

  • Don't worry about it. Under the hood there is only one GPS location provider instance running with a frequency of minimum of those two time that you have set.

    A point of concern is the 100ms interval that you have set. I think that 1 sec updates is the least interval that you can set for most GPS chipsets.