Search code examples
androidxamarinxamarin.androidtaskfusedlocationproviderclient

FusedLocationProviderClient RemoveLocationUpdatesAsync Task does not complete


I am implementing a Xamarin Android Location tracker and added following code to stop location updates.

    public Task StopAsync()
    {
        if(IsTracking)
        {
            IsTracking = false;
            perviousStopTask = fusedLocationProviderClient.RemoveLocationUpdatesAsync(this);
        }

        return perviousStopTask;
    }

Above method, I assign Task returns from RemoveLocationUpdatesAsync method to perviousStopTask and return it from StopAsync method. But when I try to await this StopAsync method it does not complete.


Solution

  • The Xamarin LocationSample project is placing blame on Google Play Services for this problem. The sample does not currently use await when calling RemoveLocationUpdatesAsync.

    TODO: We should await this call but there appears to be a bug in Google Play Services where the first time removeLocationUpdates is called, the returned Android.Gms.Tasks.Task never actually completes, even though location updates do seem to be removed and stop happening. For now we'll just fire and forget as a workaround.