In a customer meeting, a printed map was laid on the table. On a field technician's route there was a 40-minute gap between 12:10 and 12:50. The customer said, "Our staff member was on the construction site at that time. Your system isn't working." We talked to the technician: the phone had been in their pocket, and they hadn't opened the app, but they hadn't closed it either. We checked the server logs: not a single packet had come in from that device for 40 minutes. The app had died, and it was under no obligation to tell anyone.
The first version of the mobile app we built for tracking field staff had approached location tracking with a desktop mindset: the app opens, listens for location updates and sends them to the server. We had underestimated the war that mobile operating systems have been waging on background apps in recent years. That 40-minute gap lit the fuse on a three-month rewrite.
The First Wrong Hypothesis: "There's No GPS Signal"
Our first reflex was to blame the hardware: indoors, weak GPS signal, old device. But the data refuted that hypothesis. The gaps didn't line up with people entering buildings; they lined up with the point 15-25 minutes after the phone's screen turned off. The gaps also differed strikingly by device brand: in the pilot group, Xiaomi devices averaged 6 gaps a day, Samsungs 2, and on iPhones the pattern was something else entirely. The problem wasn't in the sky; it was in the operating system.
The Android Front: Doze and the Manufacturers' Hidden Killers
Doze mode, introduced in Android 6, confines apps' network access and timers to maintenance windows when the screen is off and the device is stationary. Our service, which sent a location every 30 seconds, first became sporadic and then went completely silent on a device that had entered Doze. The standard solution is well known: a foreground service with a persistent notification. We added one, and on stock Android the gaps all but disappeared.
But manufacturers like Xiaomi, Huawei and Oppo have their own aggressive battery managers that killed even the foreground service. MIUI's "battery saver" setting cut off the service every few hours unless the user manually added an exception. There's no technical solution to this, but there is a product solution. We added a setup wizard to the app that detects the device brand, takes the user to that brand's specific settings screen, and walks them through it step by step with visuals. It sounds like tedious work, but on its own it was the single most effective change: daily gaps on Xiaomi devices dropped from 6 to 0.4.
Meanwhile, Android's own rulebook doesn't stand still either. Android 8 brought the first major restrictions on background services, and 10 and 11 turned background location into a separate permission and removed the "allow all the time" option from the first dialog. That means you have to convince the user inside the app first and then send them to the system settings. Because behavior changes with every new Android version, our test device shelf has gotten crowded: we regularly make the rounds on nine physical devices in total, covering four manufacturers and three Android versions. Learning to trigger Doze instantly with adb's deviceidle commands instead of waiting for it cut our testing time from hours to minutes. Until we learned those commands, our test method was "put the device down, wait two hours, check the logs."

The iOS Front: Permission Diplomacy
On iOS, the wall was a different one. If location permission has been granted only "while using the app," the location stream stops the moment the app goes to the background. The path to the "always" permission has two stages, and half of our users gave up at the second one. We moved the permission request from a random moment to the moment the user sees the value: we asked right after their first shift record was successfully created, with the explanation "so that recording continues during your shift even when the app is closed." The rate of "always" permission rose from 48 percent to 81.

The second iOS trick was the significant location change service. Even if iOS evicts the app from memory, when the device moves roughly 500 meters, the system relaunches the app in the background and delivers the location. This acts as an anchor that lets a killed app bring itself back to life. Also, if you forget the allowsBackgroundLocationUpdates flag or the setting that turns off automatic pausing, the stream still gets cut off while everything looks right. We lost a whole week to exactly this.
The technical side of making peace with interruptions was a solid store-and-forward layer on the device. The app first writes every point it collects to a local SQLite buffer; if the send succeeds, the point is deleted from the buffer, and if it fails, the point waits there. The buffer is capped at 10,000 points, and if it fills up, space is freed by thinning out the oldest records (not deleting them wholesale, but dropping every second point), so the skeleton of the route survives even a long stretch offline. Every packet sent to the server carries a sequence number generated on the device, which lets the server discard duplicate sends and tell the device which ranges are still missing. Without this layer, every front won in the background war loses its meaning with a single drive through a tunnel.
Battery: Where the Other Side Has a Point
I've described the operating systems as the enemy, but what they're defending is legitimate: our pilot version ate 31 percent of the battery over an 8-hour shift. Nobody keeps an app like that alive on their phone, and users were rightly turning on the settings that killed it. So half of the technical war was cutting our own consumption. We sampled GPS in a motion-aware way rather than at a fixed interval: when the accelerometer reported no movement, we dropped location requests to one per minute, and when movement started, we raised them to one every 15 seconds. We sent packets not one by one but in groups of 20, waking up the radio only once. Consumption dropped from 31 percent to 9, and interestingly, the rate at which users manually killed the app dropped too.
Alongside the technical war, there was a human front as well, and a solution that ignores it doesn't survive. The person being tracked is an employee, and iOS already announces an app using location in the background with a blue bar, as Android does with a persistent notification; covert tracking simply isn't an option, legally or technically. Along with the setup package, we gave our customers a privacy notice template and an "off-hours tracking disabled" default. The app has a defined shift window: when the shift ends, location collection stops, and users can see this on their screen. What's interesting is that this transparency improved the technical metrics too. Users who know when they're being tracked, and who have consented to it, stop manually killing the app.

There's No Such Thing as Gap-Free Data
There's also the measurement side of all this: in this three-month war, metrics were the only way we could see what worked and what didn't. We collect a daily health summary from every device: how many points were generated, how many arrived on time, how many minutes the longest silence lasted, and how many times the app restarted. Without these summaries, the only answer to "is it fixed on Xiaomi?" would have been the absence of customer complaints, which is the most expensive measurement method there is. Thanks to the health dashboard, we saw that one manufacturer's new ROM update had started killing our service again, days before the first complaint came in.
At the end of three months, the gaps hadn't disappeared, but they had become manageable. The average daily downtime per device dropped from 47 minutes to under 4 minutes. The real maturing, though, happened on the server side: we rebuilt the rest of the system on the assumption that data can arrive late and have holes in it. The device buffers data while offline and sends it in bulk later, the server slots late-arriving points into place by timestamp, and reports clearly distinguish between "no data" and "no movement." In mobile background location, the goal isn't zero interruptions; it's living honestly with them. If you're dealing with similar gaps in your field app, reach out here. We've filled quite a notebook on which setting breaks what, brand by brand.