Skip to content

Android background connections

Android lets apps run in the background, but it saves battery hard, and some phone makers add their own limits that can stop ZestSSH’s sessions. This page covers what ZestSSH does to stay connected and what you can change.

While a session is open, ZestSSH runs a foreground service with a notification titled ZestSSH that says how many sessions are open (for example “One active SSH session” or “3 active SSH sessions”, in your phone’s language). This tells Android the app is doing work and should not be stopped.

The notification’s channel is SSH sessions (“Shown while SSH sessions are open, so they keep running”). It is quiet on purpose: it makes no sound.

If you do not see the notification while connected:

  1. Check that ZestSSH may post notifications (Android Settings > Apps > ZestSSH > Notifications). On Android 13 and later, ZestSSH asks for this the first time you open its notifications screen (the bell).
  2. Check that the SSH sessions channel is not turned off.

ZestSSH does not ask to be left out of battery saving by itself. If sessions stop when the screen is off, set ZestSSH’s battery use to unrestricted. On stock Android this is Settings > Apps > ZestSSH > Battery > Unrestricted. Phone makers name and place this setting differently; dontkillmyapp.com lists the steps for each maker.

Do not use Force stop on ZestSSH: it ends every session and every scheduled task.

A keepalive is a small message ZestSSH sends over a quiet connection, so routers and firewalls do not drop it as idle.

  • For every host: on a phone, Settings > Terminal and SSH > Keepalive interval (on a computer, Settings > Terminal and SSH > SSH keepalive interval). The default is 30 seconds; 0 turns it off.
  • For one host: Keepalive interval in the host’s editor, where Use global default follows the setting above, or you choose 15, 30 or 60 seconds, 2 minutes or another value.

If three keepalives in a row go unanswered and nothing else comes from the server, ZestSSH ends the session as lost: the host stopped answering. At the default of 30 seconds that takes about 1.5 to 2 minutes.

If a mobile network drops idle connections after a few minutes, a shorter keepalive (15 seconds) helps.

Auto reconnect is on by default. When a session drops unexpectedly, ZestSSH connects it again by itself: up to 10 tries, waiting 2, 4, 8 and 16 seconds, then 30 seconds between tries. The session shows which try it is on, with Cancel, and what the last try said.

You can turn it off in a session’s terminal settings on a phone, or under Settings > Terminal and SSH on a computer.

A new connection is a new shell. To get back to what was running, use tmux on the server: see tmux workflow.

Keep screen awake (“Prevent screen dimming during sessions”) is on by default, in Settings > Terminal and SSH on a phone. While a session is open in front, the screen stays on, so Android does not lock the phone and push ZestSSH to the background.

Scheduled automation tasks use Android’s WorkManager. Android runs them at least 15 minutes apart, and may run them later than planned when the phone is in Doze or saving battery. The battery setting above helps them run on time. When ZestSSH is not on screen, Android does not let it start a task by itself, so a task that is due shows a notification, A scheduled task is ready, and runs when you tap it. Let ZestSSH post notifications, or such tasks do not run. See Scheduled tasks and Android background automation.

Set battery use to unrestricted (above), and check that the foreground notification is there while connected.

Sessions drop when you switch between Wi-Fi and mobile data

Section titled “Sessions drop when you switch between Wi-Fi and mobile data”

A TCP connection belongs to one network, so changing network breaks it. Auto reconnect connects the session again. Run tmux on the server to keep your work: tmux workflow.

The connection drops after the same number of idle minutes

Section titled “The connection drops after the same number of idle minutes”

Your network drops idle connections. Set a keepalive shorter than that time (15 seconds works for most mobile networks).

  1. Connect to a server in ZestSSH.
  2. Run watch -n 5 date on the server (it prints the time every 5 seconds).
  3. Switch to other apps for 5 to 10 minutes.
  4. Switch back. If the output has no gaps, background sessions work.
  5. Lock the screen for 5 to 10 minutes, then unlock, and check the session again.