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. |