Browse SDKs · Android
Platform
SDKsAndroid

Clear messages in a conversation

Purge all local and remote messages from a specific conversation while preserving the conversation entry.

Copy

Purge all historical messages from a conversation while preserving the conversation entry itself in the chat list. Use this operation when the user wants to wipe message history without removing the chat contact or group item.

Code example

OpenIMClient.getInstance().messageManager.clearConversationAndDeleteAllMsg(
    conversationID,
    new OnBase<String>() {
        @Override
        public void onSuccess(String data) {
            // Messages cleared successfully.
        }

        @Override
        public void onError(int code, String error) {
            // code and error describe the failure.
        }
    }
);

Parameters

ParameterTypeRequiredDescription
conversationIDStringYesTarget conversation identifier.
baseOnBase<String>YesCallback delivering the asynchronous operation result.

Return value

The successful callback indicates that all messages for the specified conversation were deleted locally and remotely. The conversation entry remains in the chat list, but its latest message preview (latestMsg) is cleared.

State changes after the call

Purging messages triggers the OnConversationListener.onConversationChanged event. Locate the conversation by conversationID, reset message history in active chat views, and clear the latest message preview in the list. For complete listener registration details, see Get the conversation list. To delete the conversation entry alongside its messages, see Delete a conversation and its messages.