0

I am trying to use fused location provider to capture location in background every half an hour with PRIORITY_HIGH_ACCURACY. To achieve this, I have used PendingIntent with BroadcastReceiver and requesting for a location update every thirty minutes. Open questions:-

1. Even though the documentation says setInterval(long duration) in inexact in nature, I am not getting location updates at all for several hours at times. In fact, it looks like it has stopped getting location updates completely sometimes.

2. Even though GPS is ON all the time and in movement, at times I get the location as NULL which is worrisome.

Above issues makes the location update logic in background not very reliable. I can use Alarm manager to wake every half hour and request for a location update but this looks an overhead, further this also may not guarantee the location update received will not be NULL.

Any thoughts?

Kaps
  • 2,345
  • 2
  • 26
  • 37
  • 1
    there is never a guarantee that a location will be returned to you so you always have to handle a null location – tyczj Aug 25 '15 at 16:21
  • Can we somehow ensure that a location update is triggered in around half an hour? unlike usual behavior where it is not triggered for hours/days some times? I know this will not be optimum from System's perspective but is there is any API that supports such behavior? – Kaps Aug 26 '15 at 01:24
  • sure dont use `setInexactRepeating` and use `setExact` – tyczj Aug 26 '15 at 01:27
  • There are no apis like setInexactRepeating or setExact. The api exposed is setInterval in LocationRequest class. Am I missing something here? – Kaps Aug 26 '15 at 01:44
  • I thought you were using `AlarmManager`? AlarmManager is the only way to guarantee your location service is fired at the correct time – tyczj Aug 26 '15 at 02:18
  • I haven't used it yet assuming that request for location updates every 30 minutes should be nice to use, when it is meant to be used like that. A deviation of 5-10 minutes for a capture every 30 minutes should be acceptable, but as I said, at several occasions update do not trigger at all making it unreliable. Knowing that AlarmManager will be an overhead I need to switch to that I guess. – Kaps Aug 26 '15 at 05:14
  • What does your Location Request code look like? – andrewdleach Aug 29 '15 at 03:46
  • hey..sorry for late response. I am using below post for this,https://uncorkedstudios.com/blog/background-location-updates-on-android – Kaps Sep 03 '15 at 06:43

0 Answers0