harmony 鸿蒙DataAbility Switching

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

DataAbility Switching

The DataAbility component in the FA model corresponds to the DataShareExtensionAbility component in the stage model.

The DataShareExtensionAbility class provides system APIs. Only system applications can create DataShareExtensionAbility instances. Therefore, DataAbility switching adopts different policies for system applications and third-party applications.

Switching a DataAbility for a System Application

The procedure for switching a DataAbility for a system application is similar to the procedure of PageAbility switching.

  1. Create a DataShareExtensionAbility in the stage model.

  2. Migrate the DataAbility code to the DataShareExtensionAbility.

    The table below describes the lifecycle comparison of the DataAbility and DataShareExtensionAbility.

|DataAbility|DataShareExtensionAbility|Comparison Description| |——–|——–|——–| |onInitialized?(info: AbilityInfo): void|onCreate?(want: Want, callback: AsyncCallback<void>): void
|The two methods have the same invoking time but different input parameters. In the stage model, the want parameter is added so that you can obtain parameters during creation.| |update?(uri: string, valueBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void|update?(uri: string, predicates: dataSharePredicates.DataSharePredicates, value: ValuesBucket, callback: AsyncCallback<number>): void|The two methods have the same meaning and invoking time, but slightly different parameter sequence and parameter type. A simple reconstruction is required.| |query?(uri: string, columns: Array<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void|query?(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>, callback: AsyncCallback<Object>): void;|The two methods have the same meaning and invoking time, but slightly different parameter sequence and parameter type. A simple reconstruction is required.| |delete?(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void|delete?(uri: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>):|The two methods have the same meaning and invoking time, but slightly different parameter type. A simple reconstruction is required.| |normalizeUri?(uri: string, callback: AsyncCallback<string>): void|normalizeUri?(uri: string, callback: AsyncCallback<string>): void|The two methods have the same meaning, invoking time, and parameters.| |batchInsert?(uri: string, valueBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback<number>): void|batchInsert?(uri: string, values: Array<ValuesBucket>, callback: AsyncCallback<number>): void|The two methods have the same meaning and invoking time, but slightly different parameter type. A simple reconstruction is required.| |denormalizeUri?(uri: string, callback: AsyncCallback<string>): void|denormalizeUri?(uri: string, callback: AsyncCallback<string>): void|The two methods have the same meaning, invoking time, and parameters.| |insert?(uri: string, valueBucket: rdb.ValuesBucket, callback: AsyncCallback<number>): void|insert?(uri: string, value: ValuesBucket, callback: AsyncCallback<number>): void|The two methods have the same meaning and invoking time, but slightly different parameter type. A simple reconstruction is required.| |openFile?(uri: string, mode: string, callback: AsyncCallback<number>): void|NA|The stage model does not support cross-process URI access. You are advised to use the want parameter to carry the file descriptor and file information for cross-process file access.| |getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>): void|NA|The stage model does not support cross-process URI access. You are advised to use the want parameter to carry the file descriptor and file information for cross-process file access.| |getType?(uri: string, callback: AsyncCallback<string>): void|NA|The stage model does not support cross-process URI access. You are advised to use the want parameter to carry the file descriptor and file information for cross-process file access.| |executeBatch?(ops: Array<DataAbilityOperation>, callback: AsyncCallback<Array<DataAbilityResult>>): void|NA|This method is not provided in the stage model. You need to implement the functionality based on service functions.| |call?(method: string, arg: string, extras: PacMap, callback: AsyncCallback<PacMap>): void|NA|This method is not provided in the stage model. You need to implement the functionality based on service functions.|

Switching a DataAbility for a Third-Party Application

In the stage model, third-party applications cannot provide data services for other third-party applications. You can select a switching solution based on your service requirements.

Service Type Switching Solution
Providing data for third-party applications Match a scenario-specific ExtensionAbility.
Providing data within the application Extract the component code as a common module for other components to use.

你可能感兴趣的鸿蒙文章

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  赞