harmony 鸿蒙@ohos.application.BackupExtensionAbility (BackupExtensionAbility)

  • 2023-10-30
  • 浏览 (374)

@ohos.application.BackupExtensionAbility (BackupExtensionAbility)

The BackupExtensionAbility module provides extended backup and restore capabilities for applications.

NOTE

The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.

The APIs of this module can be used only in the stage model.

Modules to Import

import BackupExtension from '@ohos.application.BackupExtensionAbility';

BundleVersion

Defines the version information required for data restore. You can determine the application data to be restored based on the version information.

System capability: SystemCapability.FileManagement.StorageService.Backup

Name Type Mandatory Description
code number Yes Internal version number of the application.
name string Yes Version name of the application.

BackupExtensionAbility

Implements backup and restore for application access data. You can use onBackup and onRestore to implement custom backup and restore operations.

Attributes

System capability: SystemCapability.FileManagement.StorageService.Backup

Name Type Readable Writable Description
context11+ ExtensionContext Yes No Context of the BackupExtensionAbility. It inherits from Context.

onBackup

onBackup(): void;

Called when data is being backed up. You need to implement extended data backup operations.

System capability: SystemCapability.FileManagement.StorageService.Backup

Example

  class BackupExt extends BackupExtension {
    async onBackup() {
      console.log('onBackup');
    }
  }

onRestore

onRestore(bundleVersion: BundleVersion): void;

Called when data is being restored. You need to implement extended data restore operations.

System capability: SystemCapability.FileManagement.StorageService.Backup

Parameters

Name Type Mandatory Description
bundleVersion BundleVersion Yes Version information of the application data to be restored.

Example

  import type { BundleVersion } from '@ohos.application.BackupExtensionAbility';
  class BackupExt extends BackupExtension {
    async onRestore(bundleVersion : BundleVersion) {
      console.log(`onRestore ok ${JSON.stringify(bundleVersion)}`);
    }
  }

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞