harmony 鸿蒙DataAbility Lifecycle

  • 2023-02-03
  • 浏览 (595)

DataAbility Lifecycle

You can override lifecycle callbacks (described in the table below) for a DataAbility based on service requirements.

Table 1 DataAbility lifecycle APIs

API Description
onInitialized?(info: AbilityInfo): void Called during ability initialization to initialize the relational database (RDB).
update?(uri: string, valueBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void Updates data in the database.
query?(uri: string, columns: Array<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void Queries data in the database.
delete?(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void Deletes one or more data records from the database.
normalizeUri?(uri: string, callback: AsyncCallback<string>): void Normalizes the URI. A normalized URI applies to cross-device use, persistence, backup, and restore. When the context changes, it ensures that the same data item can be referenced.
batchInsert?(uri: string, valueBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback<number>): void Inserts multiple data records into the database.
denormalizeUri?(uri: string, callback: AsyncCallback<string>): void Converts a normalized URI generated by normalizeUri into a denormalized URI.
insert?(uri: string, valueBucket: rdb.ValuesBucket, callback: AsyncCallback<number>): void Inserts a data record into the database.
openFile?(uri: string, mode: string, callback: AsyncCallback<number>): void Opens a file.
getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>): void Obtains the MIME type of a file.
getType?(uri: string, callback: AsyncCallback<string>): void Obtains the MIME type matching the data specified by the URI.
executeBatch?(ops: Array<DataAbilityOperation>, callback: AsyncCallback<Array<DataAbilityResult>>): void Operates data in the database in batches.
call?(method: string, arg: string, extras: PacMap, callback: AsyncCallback<PacMap>): void Calls a custom API.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Application Models

harmony 鸿蒙Using Explicit Want to Start an Application Component

harmony 鸿蒙Using Implicit Want to Open a Website

harmony 鸿蒙AbilityStage Component Container

harmony 鸿蒙Accessing a DataAbility

harmony 鸿蒙Accessing a DataShareExtensionAbility from the FA Model

harmony 鸿蒙AccessibilityExtensionAbility

harmony 鸿蒙Common action and entities Values

harmony 鸿蒙API Switching Overview

harmony 鸿蒙Switching of app and deviceConfig

0  赞