Browse SDKs · Android
Platform
SDKsAndroid

Clear all saved messages

Use deleteAllMsgFromLocalAndSvr to clear local and server-side messages.

Copy

Clear all message records stored both in the local SQLite database and on the remote server for the logged-in account. This operation is permanent and irreversible; once executed, historical message data for the current account cannot be restored. This operation clears only the caller's message mailbox and does not delete message copies retained by other participants or alter friend and group relationships.

Code example

OpenIMClient.getInstance().messageManager.deleteAllMsgFromLocalAndSvr(
    new OnBase<String>() {
        @Override
        public void onSuccess(String data) {
            // Local and server messages cleared successfully
        }

        @Override
        public void onError(int code, String error) {
            // Handle clearing failure
        }
    }
);

Parameters

ParameterTypeRequiredDescription
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 message records across all conversations were purged from both local storage and the server for this account. Clear open chat message views.
  2. Conversation summary update: The last message preview (latestMsg) on conversations is cleared or refreshed to reflect the empty state.
  3. Re-query calibration: To delete only the local offline cache on this device while retaining cloud roaming history, call Clear all local messages.