android - FusedLocationProviderClient RemoveLocationUpdatesAsync 任务未完成

标签 android xamarin xamarin.android task fusedlocationproviderclient

我正在实现 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/

相关文章:

android - 获取手机的IMEI

xamarin.forms - Xamarin 表单检查键盘是否打开

Android Studio 拒绝在我的手机上构建和安装任何应用

Java - 从文件中读取混合数据类型(char + int + 二进制)

android - Android如何用圆圈显示字母

android - 如何关闭所有基础 Activity

android - MapWithOverlaysActivity - 无法确定 $(TargetFrameworkVersion)

c# - 如何在 .NET Core 中使用 xUnit 测试 Xamarin ViewModel?

android - 如何检测 View 寻呼机垂直滑动并将该事件发送到下面的布局?

rest - Visual Studio 无法在我的 rest api 客户端中添加 swagger 元数据文件