Disconnect
After connecting to the service, you can disconnect from the IM connection when switching users or logging out. You can also configure whether the user receives push notifications after disconnecting.
Chat UI SDK automatically reconnects when the app switches between foreground and background or when network issues occur, ensuring connection reliability. Unless your app logic requires a logout, you do not need to call this method to manually disconnect.
Disconnect (allow push)
Actively disconnect from the server and allow the server to send remote push notifications after disconnection.
- Kotlin
- Java
NCChatUI.disconnect()
NCChatUI.disconnect();
When the server detects that the app client is offline (by default, all devices must be offline), it records an offline message? for the user upon receiving a new message and triggers the push service. The server sends a notification through the push channel to the client SDK. This notification typically appears in the notification panel to alert the user about offline messages.
Disconnect (disallow push)
Actively disconnect from the server and disallow the server from sending remote push notifications after disconnection.
When logging out or switching app user accounts, use the following method:
- Kotlin
- Java
NCChatUI.logout()
NCChatUI.logout();
When disconnected with push disabled, the server only records offline messages but does not trigger the push service for the current device. If the user is logged in on multiple devices, the last logged-in device among the other devices can still receive push notifications normally. In multi-device scenarios, if your app needs to maintain consistent message records across devices, enable multi-device message sync. See Multi-device message sync for details.