重启后如何接收位置更新

How to receive location updates after reboot

我正在使用此示例接收位置更新:

https://github.com/googlesamples/android-play-location/tree/master/LocationUpdatesPendingIntent

它在我使用 Google API 客户端的连接实例注册位置请求后接收位置。 我的问题是如何在设备重启后重新注册 Google Api 客户端?有人说AndroidO会限制后台服务,所以不推荐一个服务?

我发现这个 link 很有用,但仍然不知道 OS 的实际行为以及是否将我的应用程序视为前台或后台?

https://developer.android.com/preview/features/background.html#services

My question is how can I re-register Google Api Client after device reboots?

ACTION_BOOT_COMPLETED 广播的清单中注册 BroadcastReceiver。然后,在其 onReceive() 方法中,重新注册您的位置更新请求。

Some say Android O will put restrictions on background services, so a service is not recommended?

您是使用服务来注册位置更新还是处理位置更新取决于在这两个点上需要做的工作。如果您正在做任何类型的 I/O(磁盘 I/O、网络 I/O 等),您应该使用服务。

Android O 改变的是:

  • 纯后台服务只能运行一分钟左右;如果您可能需要更多时间,则需要考虑使用前台服务

  • 向后台应用传送位置更新的频率会降低