我正在实现 Xamarin Android 位置跟踪器并添加以下代码以停止位置更新。
public Task StopAsync()
{
if(IsTracking)
{
IsTracking = false;
perviousStopTask = fusedLocationProviderClient.RemoveLocationUpdatesAsync(this);
}
return perviousStopTask;
}
在上述方法中,我将任务从 RemoveLocationUpdatesAsync
方法返回分配给 perviousStopTask
并从 StopAsync
方法返回它。但是当我尝试等待这个 StopAsync
方法时,它没有完成。
最佳答案
Xamarin LocationSample project将此问题归咎于 Google Play 服务。该示例当前在调用 RemoveLocationUpdatesAsync
时不使用 await。
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.
关于android - FusedLocationProviderClient RemoveLocationUpdatesAsync 任务未完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55219622/