How BLE reconnection fails on Android, and how to fix it
Most BLE instability on Android comes from five patterns, not one bug. Each has a fix, and one architecture prevents all five.
Surendra — Tejvon
Senior Android & BLE Engineer
Android's Bluetooth Low Energy stack is unreliable out of the box. In our experience the instability is rarely one bug. It comes from five patterns that combine, and each has a specific fix.
Cached services. Android caches the result of service discovery for each device. After a firmware update changes the device's services, the app can keep using stale characteristics and fail without an error. Call close() on the previous connection before reconnecting: disconnect() alone does not release it. Use autoConnect set to false for connections the user starts.
Callback threading. GATT callbacks arrive on a background thread, and the stack is not thread-safe. Starting the next operation from inside a callback, on the wrong thread, is a common source of the infamous status 133. Move every GATT call to one thread, which coroutines make straightforward.
Lifecycle leaks. If a screen is destroyed while it holds a connection, the system connection survives and the app loses its reference. The next connect creates a second client. Phones support only a small number of GATT clients at once, and once they are used up every connection fails until the Bluetooth stack restarts. Keep connection state out of screens: in a ViewModel, a service or an application-scoped manager.
Manufacturer differences. Timing, battery optimisation and error codes vary between phone makers. Writing a code path per manufacturer does not scale. Retry with exponential backoff, and test on a representative set of devices before every release.
MTU reset. The MTU, the maximum packet size, is negotiated per connection and falls back to the 23-byte default on every reconnect. An app that reuses the old value sends writes the device rejects. Request the MTU again after service discovery, every time. The usable payload is the negotiated MTU minus 3 bytes of header.
What ties these together is the lack of explicit state. Code that reacts to each callback on its own can sit in an undefined state between them. The fix is a state machine: disconnected, connecting, connected, discovering, ready, disconnecting. Only operations valid in the current state are allowed, any unexpected transition triggers a clean teardown and reconnect, and the state is exposed as a flow the rest of the app observes.
With that structure in place, most reconnection problems stop being mysteries. The log shows which state the connection reached and what event arrived, and that usually names the problem.
Topics
Working on a similar challenge?
Let's discuss the architecture before you build.
BLE system design, OTA reliability, and connected product engineering — this is what TEJVON does every day.
Book a Technical Consultation