public void closeConnection() { maintainConnection = false; if (keyboard != null) { // Tell the server to release any meta keys. keyboard.clearMetaState(); keyboard.processLocalKeyEvent(0, new KeyEvent(KeyEvent.ACTION_UP, 0)); } // Close the rfb connection. if (rfbconn != null) rfbconn.close(); // rfbconn = null; // rfb = null; // cc = null; // sock = null; // Close the SSH tunnel. if (sshConnection != null) { sshConnection.terminateSSHTunnel(); sshConnection = null; } onDestroy(); }