【发布时间】:2017-06-16 19:06:38
【问题描述】:
我写了以下服务,想法是在应用程序启动时将用户位置发送到服务器,当用户旅行超过500m时,问题是在启动时它调用onLocationChanged 3次。
我无法理解它从哪里调用它 3 次。请指导我如何解决此问题。
public class LocationUpdateService extends Service implements
LocationListener,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private static final long BACKGROUND_INTERVAL = 60000;
final private String TAG = LocationUpdateService.class.getSimpleName();
private LocationRequest mLocationRequest;
private GoogleApiClient mGoogleApiClient;
private String LOCATION_PREF = "LOCATION_PREF";
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "onStartCommand: ");
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(BACKGROUND_INTERVAL);
mLocationRequest.setFastestInterval(30000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
mLocationRequest.setSmallestDisplacement(500);
super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
@Override
public void onLocationChanged(Location location) {
Log.i("Location Service", "onLocationChanged: " + location.toString());
saveLocationandReport(String.valueOf(location.getLatitude()), String.valueOf(location.getLongitude()));
}
【问题讨论】:
标签: android performance android-layout locationlistener android-fusedlocation