Skip to main content

Monitor Connection Status

The client SDK provides an IM connection status listener, ConnectionStatusListener, for apps. By monitoring changes in the IM connection status, apps can handle different business logic or display prompts on the interface.

Connection Status Listener Overview

The ConnectionStatusListener interface is defined as follows:

  public interface ConnectionStatusListener {
void onChanged(ConnectionStatus status);
}

When the connection status changes, the SDK will callback the current connection status to developers via the onChanged() method. Refer to the table below for detailed descriptions of each status.

Status NameStatus ValueDescription
NETWORK_UNAVAILABLE-1Network unavailable
CONNECTED0Connection successful
CONNECTING1Connecting
UNCONNECTED2Disconnected state, meaning the app has not called the connect method
KICKED_OFFLINE_BY_OTHER_CLIENT3The user account logged in on another device, causing this device to be kicked offline
TOKEN_INCORRECT4Triggered when the Token expires
CONN_USER_BLOCKED6User banned via the Console
SIGN_OUT12State where the user actively disconnects, see Disconnect
SUSPEND13Connection temporarily suspended (usually due to network issues), the SDK will automatically reconnect at an appropriate time
TIMEOUT14Connection timeout, the SDK will stop connecting, and the user needs to handle the timeout and manually call the Connect Interface to reconnect

Add or Remove Connection Status Listeners

The SDK supports setting multiple listeners. It is recommended to set them within the app's lifecycle.

To avoid memory leaks, remove the listeners when they are no longer needed.

// Add a connection status listener since 5.1.6
RongCoreClient.addConnectionStatusListener(listener);
// Remove a connection status listener since 5.1.6
RongCoreClient.removeConnectionStatusListener(listener);