SDKsAndroidEnterprise
Delete messages in a batch
Delete multiple messages from one conversation for the current account with the Android SDK.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
request | DeleteMessagesReq | Yes | Batch deletion request object containing conversationID, an array of clientMsgIDs to delete, and the isSync synchronization flag. |
base | OnBase<String> | Yes | Callback handler for the asynchronous request. |
Return value
Upon success, data in onSuccess returns a confirmation message.
State changes after the call
- Callback confirmation: The
onSuccesscallback indicates that the messages were deleted from local storage and the server. Remove the deleted items from the active UI list usingclientMsgID. - Asynchronous event delivery: When
isSync = true, other client devices logged into the same account receive deletion notifications throughOnAdvanceMsgListener.onMsgDeleted. Clients should remove matching messages usingclientMsgID. - Re-query calibration: If message lists diverge, reload messages via Load older messages.
For complete listener registration and lifecycle management, see Receive messages.
Was this page helpful?