Disconnect
Disconnect from the Nexconn server when a user switches accounts or logs out. You control whether the device continues to receive push notifications after disconnecting.
The Chat SDK automatically reconnects when the app switches between foreground and background or when network conditions change. Only call disconnect when your app logic explicitly requires it, such as during logout.
Disconnect from the server
Call disconnect to close the connection to the Nexconn server. Use the disablePush parameter to control whether push notifications continue after disconnection.
- Kotlin
- Java
// Disconnect but keep receiving push notifications (default)
NCEngine.disconnect()
// Equivalent to
NCEngine.disconnect(disablePush = false)
// Disconnect and stop receiving push notifications (for logout)
NCEngine.disconnect(disablePush = true)
// Disconnect but keep receiving push notifications (default)
NCEngine.disconnect();
// Equivalent to
NCEngine.disconnect(false);
// Disconnect and stop receiving push notifications (for logout)
NCEngine.disconnect(true);
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| disablePush | Boolean | No | false | Whether to disable push notifications after disconnecting. • false: Continue receiving push notifications (for account switching or backgrounding).• true: Stop receiving push notifications (for logout). |
Usage scenarios
Account switching (keep push enabled)
Switch to a different user account while keeping push notifications active for the original user:
- Kotlin
- Java
// 1. Disconnect the current user (keep push)
NCEngine.disconnect(disablePush = false)
// 2. Get the new user's access token
val newToken = getNewUserTokenFromServer()
// 3. Connect as the new user
NCEngine.connect(ConnectParams(newToken)) { userId, error ->
// Handle connection result
}
// 1. Disconnect the current user (keep push)
NCEngine.disconnect(false);
// 2. Get the new user's access token
String newToken = getNewUserTokenFromServer();
// 3. Connect as the new user
NCEngine.connect(new ConnectParams(newToken), (userId, error) -> {
// Handle connection result
});
Logout (disable push)
Log the user out and stop all push notifications:
- Kotlin
- Java
// 1. Disconnect and disable push
NCEngine.disconnect(disablePush = true)
// 2. Clear local user data
clearLocalUserData()
// 3. Navigate to the login screen
goToLoginPage()
// 1. Disconnect and disable push
NCEngine.disconnect(true);
// 2. Clear local user data
clearLocalUserData();
// 3. Navigate to the login screen
goToLoginPage();
Push notification behavior
disablePush = false (push enabled)
When the Nexconn server detects that the client is offline (all devices for the user are disconnected by default), incoming messages are stored as missed messages and trigger the push notification service.
If your app integrates a vendor push channel provided by Nexconn, the server delivers a push notification through that channel. The notification typically appears in the system notification panel, alerting the user to unread messages.
disablePush = true (push disabled)
The server stores missed messages but does not trigger push notifications for the disconnected device.
If the user is signed in on multiple devices, push notifications are delivered to the last device that connected. To keep message history consistent across devices in a multi-device scenario, enable multi-device message sync. See Multi-device message sync for details.