我们说我有GoogleApiClient
个实例和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 );
稍后,我想将listenerA
替换为listenerB
。什么是最好(推荐)的方法来实现这一目标?
通过
LocationServices.FusedLocationApi.removeLocationUpdates( gac, listenerA );
LocationServices.FusedLocationApi.requestLocationUpdates( gac, requestB, listenerB );
或通过:
gac.disconnect();
gac.connect();
并在onConnected()
方法
@Override
public void onConnected( Bundle state ) {
LocationServices.FusedLocationApi.requestLocationUpdates( gac, requestB, listenerB );
}
我的问题是,在某些情况下listenerB.onLocationChanged()
没有被调用......
TIA