While you're in a JuiceSSH session (SSH, Mosh or telnet), you can safely switch between applications, and JuiceSSH will keep your SSH session running in the background.


You can also open multiple sessions at once in JuiceSSH and easily switch between them. To do this, just press the back button on your device while in the terminal. Press it once to hide the keyboard, then again to show this popup:



Select Yes to leave the session running in the background. You can now open more sessions in JuiceSSH. 


To quickly switch between the active sessions in JuiceSSH, use the notification drawer on your Android device. Each active SSH session will have it's own notification. Tap the notification for the session you want to open, and you'll be taken straight back to it.



Why do my JuiceSSH sessions fail when they are in the background?

JuiceSSH will do everything it can to keep active sessions in the background alive, however there are a few common issues that can arise.


1. Loss or change in device connectivity


The first and most common issue is that you lost connectivity to your SSH server at some point. SSH connections require constant communication between the device JuiceSSH is running on, and your SSH host. If your network changes (e.g. between mobile data and wifi), or you lose connectivity completely - it will cause a failed connection.


To avoid this being an issue, you should look into using Mosh with JuiceSSH instead of SSH. Mosh is easy to setup on a server, and not only works better over high latency connections, but also allows you to lose connectivity or roam between networks without losing connectivity. To find out more, see https://juicessh.com/mosh.


2. Battery Optimization applications or settings on your device


The second reason why connections might fail is overly aggressive battery optimization on some Android devices.


This is particularly relevant if you are using a Huawei or Xiomi device - which are very agressive in their optimization.


When a JuiceSSH session is established, we aquire an Android WAKELOCK (and a WIFILOCK too if it's an SSH session). This ensures that the device CPU stays awake, and does not terminate the background session.


Some devices (such as the above mentioned manufacturers) either silently prevent JuiceSSH from taking a these locks, or remove them after a short amount of time. Either of these situations will cause a failed connection in JuiceSSH.


To read more about the battery optimizations on these devices, and the measures you can take against them, please go to this link, and click on your device manufacturer:


https://dontkillmyapp.com/