Skip to content

Connected devices: Your device did not break. The phone closed the app.

Most dropped Bluetooth connections come from the phone, not the firmware. Here is what iOS and Android do, and how to design around it.

CoreFinity Tech5 minute read

A connected device is only as good as its connection to the phone. When that connection drops, the user does not blame the operating system. They blame the device, and often they return it.

Most dropped Bluetooth connections are not bugs in the firmware. They come from the phone itself, which closes background work to save battery. This guide covers what iOS and Android actually do, the tools each one gives you, and how to design a device and its app so a lost connection never loses data.

Why phones close Bluetooth connections

Phones have small batteries and dozens of apps that would all like to run in the background. Apple and Google handle this the same way: once an app leaves the screen, the system limits what it can do, and after a while it stops the app entirely. A companion app holding a Bluetooth connection is exactly the kind of background work the system wants to stop.

The four states a companion app passes through, and whether the Bluetooth link survives eachWhere the connection is lostThe further right the app goes, the more the operating system decides for it.Foregroundapp on screenconnection always worksBackgroundscreen off or another app openworks if the platform allows itSuspendedthe system paused the appiOS restores it, Android needs a serviceClosed by the userswiped awaynothing can run until it is openedDesign for the right hand box first. The device has to cope when the app is gone.
Each step to the right gives the operating system more control over your app.Scroll sideways to see the whole diagram.

The four states matter because each one needs a different answer. Code that works perfectly while the app is on screen can fail the moment the screen locks, and testing on a desk with the app open will never show it.

iOS: Core Bluetooth state restoration

On iOS, an app that declares the Bluetooth background mode keeps its connections while it is in the background. When memory runs low, the system may still suspend the app and then end it. State preservation and restoration is how Apple lets a Bluetooth app survive that. The app opts in when it creates its Bluetooth manager, and the system keeps track of its connections and pending requests on its behalf.

When the device reconnects, sends a notification or completes a pending request, iOS relaunches the app in the background and hands back the state it saved. The app has a short window to restore its Bluetooth manager and handle the event, so that code has to be fast and has to run before anything else at launch.

What state restoration will not do

  • Relaunch an app the user swiped away in the app switcher.
  • Relaunch an app after Bluetooth was turned off and on again in settings.
  • Keep a connection the app never asked the system to restore.

The first point catches most teams out. When a user closes the app by swiping it away, iOS treats that as a clear instruction, and nothing in Core Bluetooth will bring the app back until the user opens it again.

Android: a foreground service and the Companion Device Manager

Android gives an app more freedom in the background, and takes it away more suddenly. Without a foreground service, a backgrounded app usually loses its Bluetooth connection within minutes. A foreground service tells the system the app is doing work the user cares about, and shows a notification so the user knows it is running. On recent Android versions the service has to declare the connected device type and request the matching permission.

The Companion Device Manager goes a step further. When the user pairs the device through it, Android treats the app as the companion of that device and grants exemptions ordinary apps do not get, including permission to start its foreground service from the background when the device comes back into range. For a product that needs to stay connected all day, this is the most reliable route Android offers.

Phone makers add their own battery rules

Some manufacturers ship battery savers that go further than stock Android and close apps even while a foreground service is running, sometimes within twenty minutes. The dependable answer is to detect these phones and walk the user through allowing the app to run unrestricted, at the moment it matters, with clear steps for their exact phone.

Design the device for a missing app

Every technique above makes disconnections rarer. None of them makes disconnections impossible, so the device and the app have to treat a lost link as normal. The pattern that works is simple: the device stores readings it could not send, numbers each one, and sends them in order when the link returns.

The device buffers numbered readings while disconnected and the app syncs them in order once it reconnectsDisconnected is a normal state, not an errorEvery reading gets a sequence number, so nothing is lost and nothing is counted twice.Devicestores readings 41 to 58link downApp reconnectsasks for everything after 40Cloudignores any number it has seenThe last confirmed number is the only thing both sides have to agree on.
With sequence numbers, a reconnect is a short catch up instead of a guess.Scroll sideways to see the whole diagram.
  • The device keeps readings in a buffer sized for the longest gap you expect, with a clear rule for what to drop if it fills.
  • Each reading carries a sequence number and the time it was taken, so its place in the history is fixed whenever it arrives.
  • On reconnect, the app asks for everything after the last number it confirmed, and the cloud ignores any number it has already stored.
  • The app shows the user when data last synced, so a gap looks like a gap and the device does not look broken.

How to test it before your users do

Background behaviour only shows up in testing that copies real life. Every companion app should go through the same set of situations on real phones, including at least one phone from each manufacturer known for aggressive battery saving.

  1. Lock the screen for an hour, then check every reading arrived.
  2. Leave the phone still overnight so it reaches its deepest power saving state.
  3. Walk out of range and back again.
  4. Swipe the app away, take readings, then open the app and check the sync.
  5. Turn Bluetooth off and on, and restart the phone.
  6. Update the app while the device is connected.

A test passes only when every reading taken during it reaches the cloud once, in the right order.

That is how we build companion apps at CoreFinity Tech. The firmware, the app and the cloud are designed together around one message format, so a dropped connection becomes a short delay the user barely notices. If your device is losing data in the background, send us a short description and we will tell you where it is likely breaking.

Common questions about connected devices

Phones limit what apps can do in the background to save battery, and a companion app holding a Bluetooth connection is one of the first things they stop. iOS needs the Bluetooth background mode and state restoration, and Android needs a foreground service or the Companion Device Manager to keep the link alive.

No. When a user swipes an iOS app away, Core Bluetooth will not relaunch it, even with state restoration enabled. The device should keep its readings and sync them the next time the app opens.

The Companion Device Manager is an Android system service for pairing an app with a specific device. Apps paired through it get exemptions ordinary apps do not, including starting a foreground service from the background, which makes all day connections far more reliable.

Store readings on the device while the link is down, give each one a sequence number, and sync everything after the last confirmed number when the connection returns. The cloud ignores numbers it has already stored, so nothing is lost and nothing is counted twice.

( Before your users notice )

Stop losing readings when the phone closes the app.

Send a short description of your device and its app. We will tell you where the connection is likely dropping and what it takes to stop losing data, within 48 hours.

Ask about your dropped connections

( Related services )

( Cookies )

We would rather ask than assume.

This site sets nothing optional unless you say so. Analytics would tell us which pages are worth improving. Say no and the site works exactly the same. The cookie policy has the detail.

Strictly necessaryAlways on

Remembers this choice and keeps the site secure and working. Nothing here identifies you, and it cannot be switched off.

Strictly necessary is always on

Analytics

Counts page views so we can see which pages are worth improving. Off unless you turn it on, and we do not use it to follow you around the web.

Marketing

Would let us measure whether an advert brought you here. We run none today, so leaving this off changes nothing you can see.