Browse SDKs · Android
Platform
SDKsAndroidEnterprise

Delete messages in a batch

Delete multiple messages from one conversation for the current account with the Android SDK.

Copy

Batch-delete message records within a designated conversation for the current account. You can configure whether the deletion synchronizes to other devices logged into the same account. This deletion applies only to the current user's mailbox and does not affect message copies retained by other participants.

Code example

String conversationID = "si_user_a_user_b";
String[] selectedClientMsgIDs = new String[]{"msg_001", "msg_002"};
boolean isSync = true; // true: sync deletion to all devices; false: delete only locally and on current device's server view

DeleteMessagesReq request = new DeleteMessagesReq(
    isSync,
    conversationID,
    selectedClientMsgIDs
);

OpenIMClient.getInstance().messageManager.deleteMessages(
    request,
    new OnBase<String>() {
        @Override
        public void onSuccess(String data) {
            // Batch deletion succeeded
        }

        @Override
        public void onError(int code, String error) {
            // Failed to delete messages
        }
    }
);

Parameters

ParameterTypeRequiredDescription
requestDeleteMessagesReqYesBatch deletion request object containing conversationID, an array of clientMsgIDs to delete, and the isSync synchronization flag.
baseOnBase<String>YesCallback handler for the asynchronous request.

Return value

Upon success, data in onSuccess returns a confirmation message.

State changes after the call

  1. Callback confirmation: The onSuccess callback indicates that the messages were deleted from local storage and the server. Remove the deleted items from the active UI list using clientMsgID.
  2. Asynchronous event delivery: When isSync = true, other client devices logged into the same account receive deletion notifications through OnAdvanceMsgListener.onMsgDeleted. Clients should remove matching messages using clientMsgID.
  3. Re-query calibration: If message lists diverge, reload messages via Load older messages.

For complete listener registration and lifecycle management, see Receive messages.