If LobiShell keeps getting closed while it is in the background — your SSH session drops the moment you switch to another app, or a few minutes after the screen goes off. Sometimes its the missing battery optimization setting. But when its Set and it’s still getting closed it is your phone’s manufacturer deliberately killing it. This page explains why, and the three settings that fix it.
Why this happens
While a session is active, LobiShell runs an Android foreground service with a persistent notification. That is the mechanism Android provides for exactly this purpose, and on stock Android — Pixel, Motorola, Nokia, most tablets — it is enough on its own.
Several manufacturers layer their own background killer on top of Android. That layer does not respect the foreground service, has no public API to query, and cannot be turned off from inside an app. It has to be allowed by you, once, per app.
On a OnePlus device a system log showed the manufacturer’s own Athena process killer terminating LobiShell while the app was correctly holding an active foreground service.
Affected brands, in rough order of aggressiveness: Xiaomi / Redmi / POCO, OnePlus, OPPO, realme, vivo / iQOO, Huawei / HONOR, Samsung, Meizu, ASUS.
Fix 1 — Lock the app in Recents
This is the one that actually solves it on Xiaomi and OnePlus, and it is the step almost everyone misses. On those skins, an app that is not locked in the Recents list gets killed regardless of every battery setting you change.
This is not Android’s “Screen pinning” feature, which locks your phone to a single app. What you want is the padlock on the app’s card in the Recents / Overview screen.
| Phone | How to lock it |
|---|---|
| Xiaomi / Redmi / POCO (MIUI, HyperOS) |
Open Recents → swipe down on the LobiShell card (on some versions: long-press it) → tap the padlock icon. |
| OnePlus (OxygenOS) |
Open Recents → tap the ⋮ menu or the app icon on the LobiShell card → Lock. |
| OPPO / realme (ColorOS) |
Open Recents → drag the card down or tap the ⋮ on it → Lock. |
| vivo / iQOO | Open Recents → long-press the card → tap the padlock. |
| Huawei / HONOR | Open Recents → swipe down on the card → padlock. |
| Samsung | Open Recents → tap the app icon above the card → Keep open for quick launching. |
Once locked, “Clear all” skips the app and the manufacturer’s memory manager leaves it alone. Wording and gestures differ between firmware versions — if the exact path above does not match your phone, look for a padlock or a “Lock” entry anywhere on the app’s card in Recents.
Fix 2 — Exempt LobiShell from battery optimization
The app has a shortcut for this: Settings → Permissions → Battery Optimization → Open settings. It takes you straight to the right screen and shows whether the exemption is currently active.
Doing it manually instead: Android Settings → Apps → LobiShell → Battery → Unrestricted (older versions: “Don’t optimize”).
While you are on that screen, make sure LobiShell is not set to Restricted. That is a separate, stricter Android bucket, and it prevents background work outright.
Fix 3 — Autostart and the manufacturer’s own power menu
On the brands listed above there is a second set of switches that Android’s own battery screen does not cover. LobiShell’s Settings → Permissions screen detects a known-aggressive manufacturer and offers a button that jumps directly to the correct screen for your device, which saves hunting through the menus.
What to enable there:
| Phone | What to look for |
|---|---|
| Xiaomi / Redmi / POCO | Autostart → allow LobiShell. Then app info → Battery saver → No restrictions. |
| OnePlus | Battery → Battery optimization → LobiShell → Don’t optimize. Also disable Sleep standby optimization and, where present, Advanced optimization / Deep optimization. |
| OPPO / realme | Allow Auto-startup, and set background power consumption to Allow background running. |
| vivo / iQOO | Allow Auto-start and High background power consumption. |
| Huawei / HONOR | App launch → switch LobiShell to Manage manually and enable all three: auto-launch, secondary launch, run in background. |
| Samsung | Remove LobiShell from Sleeping apps / Deep sleeping apps, and turn off Put unused apps to sleep. |
Two more things worth checking
- Allow notifications. The persistent notification is the visible half of the foreground service that keeps the session alive. Denying it makes the mechanism weaker and leaves you with no way to see that a session is still running.
- Do not swipe the app away in Recents while a session is active. On several skins that also terminates the service. Use the back gesture or the Home button to leave the app instead.
Check that it worked
- Connect to a server.
- Switch to another app, then turn the screen off and leave it for five to ten minutes.
- Come back to LobiShell.
The persistent notification should still be there, and the session should still be live — no reconnect, and your shell history still on screen. If the notification is gone, the app was killed and one of the three settings above is still missing.
If it still happens
Send the logs from Settings → Send Feedback and Logs and mention your exact phone model and Android version. If your device kills the app even with all three settings applied, that is worth knowing — the manufacturer-specific shortcuts in the app can then be extended for your firmware.
The community-maintained site dontkillmyapp.com keeps per-manufacturer, per-version instructions for this problem, and is a good reference if your phone’s menus do not match the paths above.