4

I have the following code which is working as expected but when I request to remove location updates using the stopLocationUpdates method shown below, my onCompleteListener attached to removeLocationUpdates doesn't get triggered on the first request despite the location updates stopped as required. However, on next request, the onCompleteListener callback is triggered.

/**
 * Provides access to the fused location provider API
 */
private FusedLocationProviderClient mFusedLocationClient;


/**
 * Removes location updates from the FusedLocationApi
 */
private void stopLocationUpdates() {
    if (!mRequestingLocationUpdates) {
        // Updates were never requested.
        return;
    }

    // Remove location request when activity is in a paused or stopped state.
    mFusedLocationClient.removeLocationUpdates(mLocationCallback)
            .addOnCompleteListener(this, new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    mRequestingLocationUpdates = false;
                }
            });
}
xdzc
  • 1,421
  • 1
  • 17
  • 23

1 Answers1

2

I do not have 50 repts. to comment, so I write my comment here.

if you add an .addOnFailureListener, does it report an error like this on the second shot?

W/System.err: com.google.android.gms.common.api.ApiException: 13: listener already unregistered

RG

Update 2017.04.17:

Added .addOnFailureListener(getActivity(), new OnFailureListener()...) and .addOnSuccessListener(getActivity(), new OnFailureListener()...) and found following:

  1. None of the three(including the initial addOnCompleteListener(getActivity(), new OnCompleteListener()...)) listeners where called on this (first) removeLocationUpdate request.

  2. On the second request, addOnCompleteListener listener where called first (all seems ok) and subsequently then the onFailureListener listener with following error:

    W/System.err: com.google.android.gms.common.api.ApiException: 13: listener already unregistered

It seems that the listener does not get the first callback until the second request (is it piled up on some stack ?), and it calls (correctly?) the errorlistener to tell that the listener is already unregistered...

weird... or not ?

anyhow I will file a bugreport, if it isn't already done.

I use v11.4.2 firebase, v11.4.2 play-services, v26.1.0 android.support and v3.1.1 of com.google.gms:google-services.

RG

Roar Grønmo
  • 2,926
  • 2
  • 24
  • 37
  • 1
    Just tested this with the "LocationUpdates" example as described here: Tested both on device (android 5.0) and emulator (android 7.0), same misbehave. the listener does not get called upon 1. request, but the 2. request calls both the onComplete and onFailure (reporting already unregistered listener). Link to bug report: I hope they see it... – Roar Grønmo Oct 05 '17 at 07:01