RemoveLocationUpdates () / requestLocationUpdates () or disconnect () / requestLocationUpdates ()
let's say I have an instance GoogleApiClient
and 2 LocationListener
s:
GoogleApiClient gac = new GoogleApiClient.Builder(this)
.addApi( LocationServices.API )
.addConnectionCallbacks( this )
.addOnConnectionFailedListener( this )
.build();
LocationListener listenerA, listenerB;
LocationRequest requestA, requestB;
initTheAboveInstances();
LocationServices.FusedLocationApi.requestLocationUpdates( gac, requestA, listenerA );
At some point, I want to replace listenerA
with listenerB
. What's the best (recommended) way to do this?
By
LocationServices.FusedLocationApi.removeLocationUpdates( gac, listenerA );
LocationServices.FusedLocationApi.requestLocationUpdates( gac, requestB, listenerB );
or:
gac.disconnect();
gac.connect();
and request updates in onConnected()
@Override
public void onConnected( Bundle state ) {
LocationServices.FusedLocationApi.requestLocationUpdates( gac, requestB, listenerB );
}
?
my problem is that it listenerB.onLocationChanged()
doesn't get the call in some cases ...
TIA
+3
source to share
No one has answered this question yet
Check out similar questions: