Disconnect
After connecting to RC services, when operations such as user switching or account logout are required, you can use the following methods to disconnect from RC's IM connection. These methods also allow you to configure whether to receive push notifications after disconnection.
The IMLib SDK automatically reconnects during foreground/background switching or network exceptions to ensure connection reliability. Unless your app logic requires logout, manual disconnection using this method is unnecessary.
Disconnect (Allow Push Notifications)
Actively disconnect from RC's IM server while allowing the server to send remote push notifications after disconnection. The following two approaches achieve the same effect:
Parameter Description
| Parameter | Type | Description |
|---|---|---|
isReceivePush | Boolean | Whether to allow RC server to send remote push notifications after disconnection. true enables push notifications, false disables them. |
Sample Code
RongIMClient.getInstance().disconnect(isReceivePush);
Alternatively:
RongIMClient.getInstance().disconnect();
When the RC server detects that the app client is offline (default requires all devices to be offline), it will record an offline message? for the user upon receiving new messages, while simultaneously triggering the server's push service. If you've integrated RC's manufacturer push channels, the server will deliver a push notification through these channels to the client SDK. This alert typically appears as a notification in the status bar, informing users about offline messages.
Disconnect (Disallow Push Notifications)
When logging out or switching app user accounts, we recommend using the following methods to actively disconnect from RC's IM server while preventing the server from sending remote push notifications after disconnection. These two approaches achieve the same effect:
Parameter Description
| Parameter | Type | Description |
|---|---|---|
isReceivePush | Boolean | Whether to allow RC server to send remote push notifications after disconnection. true enables push notifications, false disables them. |
Sample Code
RongIMClient.getInstance().disconnect(isReceivePush)
Alternatively:
RongIMClient.getInstance().logout()
When disconnecting with push notifications disabled, the RC server only records offline messages without triggering push services for the current device. If the user is logged in on multiple devices, the last logged-in device will receive push notifications normally. For multi-device scenarios where apps need to maintain consistent message records across devices, enable Multi-Device Message Synchronization. See Multi-Device Message Synchronization for details.