Running a hosted android overnight without it idling out
If you’ve ever left a hosted Android session running overnight and come back to find it logged out, disconnected, or just sitting on a lock screen with a stale session token, you’ve hit the idle timeout problem. It’s not one thing. It’s three or four separate systems that all have their own idea of what “idle” means, and they don’t talk to each other.
We run real phones on dedicated hardware, not virtual devices, so every idle-out we’ve chased down has had an actual, physical explanation. Here’s what’s actually going on when a hosted Android phone stops behaving overnight, and what has to be true for it not to.
Idling out isn’t one problem
When someone says a session “idled out overnight,” they’re usually describing one of four different failures wearing the same symptom:
- The phone’s screen locked and the app running on it paused or got killed.
- Android’s power management put the app to sleep even though the screen state didn’t matter.
- The network connection between the phone and the control layer went quiet long enough that something in the middle closed it.
- The app itself, or the service it talks to, expired the session server-side because no activity came through in time.
Fixing one of these doesn’t fix the others. A phone can have its screen pinned on and still get its background process frozen by the OS. A connection can stay technically open and still be treated as dead by whatever’s watching it. You have to handle all four layers, or the phone will idle out on whichever one you missed.
The screen and the app lifecycle
Android’s screen timeout is the obvious one and the easiest to solve: set the display to stay awake, or don’t rely on the display at all. But the screen being on doesn’t actually keep an app alive. Android’s app lifecycle will still background, throttle, or kill a process based on its own rules, independent of whether pixels are lit up. A visible foreground app gets treated very differently from one sitting behind the lock screen, and a lot of automation setups accidentally end up in the second category without realizing it.
The fix here is to run the thing you need to stay alive as a proper foreground service with a persistent notification, not as a background task hoping the OS leaves it alone. A foreground service tells Android explicitly that this process matters right now. Without that signal, the OS is well within its normal behavior to suspend it, and it will.
Doze mode and app standby buckets
This is the layer that catches people who think they’ve already solved the problem. Even with the screen on and a foreground service running, Android’s power management (Doze mode when the device is stationary and unplugged, and App Standby buckets that throttle apps based on how “important” the system thinks they are) can still restrict background network access, defer alarms, and batch up work into maintenance windows.
Doze specifically triggers when a device has been stationary, unplugged, and screen-off for a stretch of time. On a phone sitting in a rack overnight with nobody touching it, that’s exactly the condition it’s designed to detect. When Doze kicks in, network access for background apps gets restricted and periodic jobs get deferred until the next maintenance window, which might be minutes away or much longer depending on how long the device has been idle.
The relevant fix is battery optimization exemption for the specific app that needs to stay reachable, combined with keeping the device on power (which changes how aggressively Doze applies) and, where you control the device at the system level, disabling adaptive battery restrictions for that package specifically. This is a per-app setting, not a global one, and it has to be set correctly or the app will get throttled the same way any consumer app would after being backgrounded for a while.
The connection layer is its own problem
This is the part people underestimate. Even if the app itself is alive, awake, and unthrottled, the actual network socket it’s using to talk to your control server can still die quietly. Carrier networks, and the NAT layers sitting between a mobile connection and the open internet, will close idle TCP connections after a period of no traffic. That period isn’t published anywhere consistent, and it varies by carrier and by how the connection is routed, but it’s real and it’s shorter than eight hours.
If your control channel doesn’t send anything for a while, the socket gets torn down somewhere in the middle without either end being told directly. The app thinks it’s still connected. The server thinks it’s still connected. Nothing is actually connected. The first sign of trouble is usually a command that goes out and just never gets acknowledged.
The fix is a heartbeat: a small, regular ping sent over the connection specifically to keep it from ever going idle long enough to get reaped. This has to happen more often than whatever the tightest NAT timeout in the path is, which in practice means erring short rather than guessing long. A heartbeat that fires every few minutes is cheap. A dead connection that silently drops your only running task overnight is not.
Server-side session expiry is a separate clock
Even with the phone awake, the app foregrounded, and the connection alive, there’s a fourth clock running: whatever session or auth timeout the app or service you’re operating actually enforces on its own end. That one has nothing to do with Android at all. It’s the app’s own idea of what counts as activity, and if the actions you’re performing overnight don’t look like activity to that specific service, it can expire the session regardless of how healthy the phone and connection are.
This is why “keeping a phone online” and “keeping a session alive” aren’t the same claim. A phone can be reachable, responsive, and fully awake, and still have every app on it logged out because nothing generated the kind of interaction the app’s own backend was watching for. If you need a session to survive overnight, you need to know what that specific app treats as a keep-alive signal, not just assume that a live phone implies a live session.
What actually has to be true, all at once
Put together, an overnight hosted Android session that doesn’t idle out needs:
- The screen kept on, or the relevant work running as a proper foreground service that doesn’t depend on the screen state at all.
- Battery optimization and adaptive battery restrictions turned off for the specific app that needs to keep running, not just a general “don’t sleep” setting.
- A device sitting on stable power, since Doze behavior changes based on charging state as much as screen state.
- A heartbeat on the control connection itself, fired often enough to beat the tightest NAT timeout in the path, not just often enough to feel reasonable.
- An understanding of what the specific app or service you’re driving actually counts as activity, since that clock runs independently of everything Android-side.
Miss any one of these and the phone will still idle out overnight, just at a different point than the one you already fixed. None of it is exotic. It’s just four separate systems that all have to be satisfied at once, on a real device, not assumed away.
If you want to see how we handle this on phones we actually operate day to day, head back to the cloudf.one home page.
Get new guides and videos first — join the Telegram channel.