Securely Backup & Restore Your Chat

Backup your chat#

Whenever you need to backup your chat messages, you can use the below method to start backup. The method will backup all the chats and writes to a file. Once backup completed you can get the backup file path from the onSuccess callback.

ArgumentTypeDescription
BACKUP_LISTENERBackupListenerlistener to observe the backup events
BackupManager.startBackup(new BackupListener() {
@Override
public void onProgressChanged(int percentage) {
}
@Override
public void onSuccess(@NonNull String backUpFilePath) {
}
@Override
public void onFailure(@NonNull String reason) {
}
});

while the backup is running, if you want to cancel the backup you can use the below method

BackupManager.cancelBackup();

Restore from a backup file#

Whenever you need to restore the chat messages from the backup file, you can use the below method.

ArgumentTypeDescription
BACKUP_FILEFilebackup file
RESTORE_LISTENERRestoreListenerlistener to observe the restore events
RestoreManager.restoreData(BACKUP_FILE, new RestoreListener() {
@Override
public void onProgressChanged(int percentage) {
}
@Override
public void onSuccess() {
}
@Override
public void onFailure(@NonNull String reason) {
}
});

while the restore backup is running, if you want to cancel the restore operation you can use the below method

RestoreManager.cancelRestore();

Note: Depending on the chat messages size the above methods may take long time for completion.

info

Cancelling restore operation will lead to partial db data, so avoid cancelling restore operation in most scenarios.