I'm working on an app which consists of a service and an activity. The service uses a LocationClient-object to request the current location every minute. The activity uses another LocationClient-object to request a single current location after a button was clicked.
In the service:
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(60000);
mLocationRequest.setFastestInterval(60000);
mLocationClient = new LocationClient(this, this, this);
// ... when connected:
mLocationClient.requestLocationUpdates(mLocationRequest, this);
In the activity:
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(0); // 0 should be ok since only a single location is requested
mLocationRequest.setFastestInterval(0);
mLocationRequest.setNumUpdates(1); // get only a single location
mLocationClient = new LocationClient(this, this, this);
// ... when connected:
mLocationClient.requestLocationUpdates(mLocationRequest, this);
The service alone works like expected.
However if the service is started and the activity tries to get a single current location then it receives the location not until the service receives an updated location. So the activity has to wait up to 60 seconds.
But if the service is not started and the activity tries to get a single current location then it receives the location after a short time like expected (usually < 5 sec.).
What is causing the problem? Is only one LocationListener per app allowed?