removeLocationUpdates()/ requestLocationUpdates()或disconnect()/ requestLocationUpdates()

时间:2014-11-30 19:37:29

标签: android location locationlistener

我们说我有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

0 个答案:

没有答案