当应用程序被杀死并且在后台使用具有待定 Intent 的 FusedLocationProviderClient 但在不规则时间时正在获取位置

Location is fetching when the app is killed and in background using FusedLocationProviderClient with pending Intent but in Irregular times

我正在使用带有未决意图的 FusedLocationProviderClient。当应用程序处于活动状态时,我正在获取位置。但是当应用程序进入后台或应用程序被杀死时,我会以不规则的时间间隔获取位置,例如 2 分钟、3 分钟、10 分钟。需要帮助吗?

注意:我也瞄准了奥利奥。

my code

如果您想在 Oreo 或更高版本的应用处于后台时获取位置数据,您应该 运行 前台服务(或类似服务):

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

使用 Oreo,Google 开始限制应用程序在后台可以执行的操作:

https://developer.android.com/about/versions/oreo/background