Skip to main content

Disconnect

When the app needs to perform operations such as switching user login or logging out, it needs to disconnect from RC's IM service. The SDK supports setting whether to allow push notifications to be sent to users after disconnecting from the IM service.

tip

The SDK automatically reconnects when the app switches between foreground and background or when network exceptions occur, ensuring connection reliability. Unless the app logic requires logout, there is no need to manually disconnect by calling this method.

Disconnect (Allow Push)

Actively disconnect from the RC server's IM service and allow the RC server to perform remote push notifications after disconnecting. The following two methods have the same effect:

RongIMClient.getInstance().disconnect()

Or:

RongIMClient.getInstance().disconnect(true)
ParameterTypeDescription
isReceivePushBooleanWhether to allow the RC server to perform remote push notifications after disconnecting. true means receiving remote push notifications. false means not receiving remote push notifications.

If the RC server detects that the app client is offline (by default, all devices must be offline), when receiving a new message, the RC server will record an offline message? for the user and trigger the RC server's push service. The RC server will send a reminder through the push channel to the client SDK. This reminder is usually displayed as a notification in the notification panel, prompting the user of an offline message.

Disconnect (Do Not Allow Push)

Actively disconnect from the RC server's IM service and set it to not allow the RC server to perform remote push notifications after disconnecting.

When logging out or switching app user accounts, it is recommended to use the following methods, which have the same effect:

RongIMClient.getInstance().logout()

Or:

RongIMClient.getInstance().disconnect(false)
ParameterTypeDescription
isReceivePushBooleanWhether to allow the RC server to perform remote push notifications after disconnecting. true means receiving remote push notifications. false means not receiving remote push notifications.

When disconnecting and not allowing push notifications, the RC 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 them can receive push notifications normally. In a multi-device scenario, the app may need to ensure consistency in message records between devices, which can be achieved by enabling Multi-Device Message Synchronization. For details, see Multi-Device Message Synchronization.