简体   繁体   English

获取后台位置更新定期停止

[英]Get background location updates periodically stops

I'm building a simple android application which basically gets the device's location periodically in the background every minute using Fused Location Services. 我正在构建一个简单的android应用程序,该应用程序基本上每分钟使用Fused Location Services在后台定期获取设备的位置。

I've implemented the application based on this tutorial https://codelabs.developers.google.com/codelabs/background-location-updates-android-o/#0 我已经根据本教程https://codelabs.developers.google.com/codelabs/background-location-updates-android-o/#0实施了该应用程序

So far the application is working fine getting the location as I need it (every minute) while I use the device every now and then. 到目前为止,当我时不时使用设备时,应用程序可以很好地获取所需的位置(每分钟)。 I tried another testing scenario where I left the device overnight to gather location updates and the day after I looked at the locations history that I'm saving for every location update. 我尝试了另一种测试方案,我整夜离开设备以收集位置更新,而第二天,我查看了要为每次位置更新保存的位置历史记录。 I noticed that the location updates were as follows: 我注意到位置更新如下:

  • first few hours location updates were every minute (as expected) 前几个小时的位置更新每分钟(与预期一样)
  • then it started getting location every approx 10 minutes for another few minutes 然后大约每10分钟开始获取位置,持续几分钟
  • then it stopped for several hours without getting any location updates 然后停止了几个小时而没有任何位置更新

After this I grabbed the device and traveled from one place to another and without even turning on the screen of the device it started getting the location updates every minute while I traveled. 此后,我抓住了该设备,从一个地方到另一个地方旅行,甚至在不打开设备屏幕的情况下,我旅行时每分钟都会开始获取位置更新。 (This might have happened coincidentally) (这可能是偶然发生的)

NOTE: The above testing scenarios were done on devices which are pre-oreo. 注意:上面的测试方案是在预原型的设备上完成的。

QUESTIONS: 问题:

  1. Could it be that the device starts getting the location updates every minute when it detects automatically that it started moving from one place to another and then it stops getting the location updates as soon as it detects that the device is at the same position for some hours? 当设备自动检测到它开始从一个位置移动到另一位置时,它可能每分钟开始获取位置更新,然后一旦检测到设备在同一位置数小时,它便停止获取位置更新。 ?

  2. Is there a recommended way to keep getting location updates always every minute and even when the device is at the same location and not being used? 是否有建议的方法可以始终保持每分钟获取位置更新,即使设备在同一位置而不被使用也是如此?

We need to keep getting location updates as the updates are being used as a heartbeat of the application. 我们需要不断获取位置更新,因为更新被用作应用程序的心跳。

you also can use this solution : 您也可以使用以下解决方案:

check if location is not received for 2 min stop and then start location update. 检查是否在2分钟内未收到位置信息,然后开始位置更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM