Skip to main content

Backup Contacts

The library provides functions for Manual and Planned backups, as well as mechanisms for tracking the backup process.

Manual Backup#

The manual backup functionality is implemented by the BackupProcessor class, which is available from the ContactManager.backupProcessor variable.

Manual backup is called as follows:


To cancel active backup, you need to call:


To track the status of a backup, you can subscribe to an observable by calling getBackupStateObservable:

private val backupStateDisposable = CompositeDisposable()
backupStateDisposable += ContactManager.backupProcessor.getBackupStateObservable()    .observeOn(AndroidSchedulers.mainThread())    .subscribe { backupState ->        when (backupState) {            is BackupProcessor.BackupState.None -> {}            is BackupProcessor.BackupState.Processing -> {}            is BackupProcessor.BackupState.Succeeded -> {}            is BackupProcessor.BackupState.Failed -> {}        }    }

The getBackupStateObservable method emits the following state objects from the BackupProcessor.BackupState object:

  • None - rest status;
  • Processing - processing status with progress progress: Float and status of the backup process backupStep: BackupStep variables.
    • The enum BackupStep has the following values:
      • COLLECTING - collection of local contacts from the device. It has a measurable progress: 0..1.
      • UPLOADING - uploading update to backend. The progress is indeterminate = -1.
      • PROCESSING - processing update on backend. The progress is indeterminate = -1.
  • Succeeded - successful completion of the backup.
  • Failed - error state, contains throwable: Throwable.

After the backup is completed, you can reset the backup state to return the UI to its original state:


To get the actual date of the last backup on device, call getLastBackupDate:

val date = ContactManager.backupProcessor.getLastBackupDate()if (date > 0) {    lastBackupValue.text = dateFormatter.format(Date(date))} else {    // no backups}

To get the latest backup date from the server, you need to call:

ContactManager.backupProcessor.refreshLastBackupDate()    .observeOn(AndroidSchedulers.mainThread())    .subscribeBy(        onSuccess = {            val date = ContactManager.backupProcessor.getLastBackupDate()            // update UI        },        onError = {}    )

Planned Backup#

The planned backup functionality is implemented by the PlannedBackupProcessor class, which is available from the ContactManager.plannedBackupProcessor variable.

To control the planned backup, you can set the backup period value:

ContactManager.plannedBackupProcessor.backupFrequency = PlannedBackupProcessor.BackupFrequency.DAILY

The enum BackupFrequency contains the following values: NONE, DAILY, WEEKLY, MONTHLY.

When starting the application, you must call the following method to check if a backup is required:


To monitor the next backup date, you need to call:

ContactManager.plannedBackupProcessor.getNextBackupTimeObservable()    .observeOn(AndroidSchedulers.mainThread())    .subscribe { nextBackupDate ->        when (nextBackupDate) {            is PlannedBackupProcessor.NextBackupDate.Date -> {                if (it.value > 0) {                    // you can schedule the application to run at a given time                 } else {                    // no backup required                }            }            is PlannedBackupProcessor.NextBackupDate.Error -> {}        }    }

The getNextBackupTimeObservable method emits the following state objects from the PlannedBackupProcessor.NextBackupDate object:

  • Date - data class which contains the date variable value: Long ;
  • Error - data class which contains the error variable throwable: Throwable .