From e7bcc151667f9df5598a0bbeaddc26b34f68c71d Mon Sep 17 00:00:00 2001 From: Annie_wang Date: Sat, 25 Feb 2023 11:05:48 +0800 Subject: [PATCH] update docs Signed-off-by: Annie_wang --- .../database/database-datashare-guidelines.md | 100 +++++++++++++----- .../database/database-mdds-guidelines.md | 18 ++-- .../database-preference-guidelines.md | 10 +- .../reference/apis/js-apis-data-dataShare.md | 2 +- .../apis/js-apis-data-distributedobject.md | 67 ++++++------ .../apis/js-apis-data-preferences.md | 42 ++++---- 6 files changed, 142 insertions(+), 97 deletions(-) diff --git a/en/application-dev/database/database-datashare-guidelines.md b/en/application-dev/database/database-datashare-guidelines.md index f0011c591e..b54f482d51 100644 --- a/en/application-dev/database/database-datashare-guidelines.md +++ b/en/application-dev/database/database-datashare-guidelines.md @@ -13,7 +13,7 @@ The **DataShare** module allows an application to manage its own data and share |query?(uri: string, predicates: DataSharePredicates, columns: Array<string>, callback: AsyncCallback<Object>): void|Queries data from the database.| |delete?(uri: string, predicates: DataSharePredicates, callback: AsyncCallback<number>): void|Deletes data from the database.| -For details about the data provider APIs, see [DataShareExtensionAbility](../reference/apis/js-apis-application-DataShareExtensionAbility.md). +For details about the data provider APIs, see [DataShareExtensionAbility](../reference/apis/js-apis-application-dataShareExtensionAbility.md). **Table 2** APIs of the data consumer @@ -34,11 +34,52 @@ There are two roles in **DataShare**: - Data provider: adds, deletes, modifies, and queries data, opens files, and shares data. - Data consumer: accesses the data provided by the provider using **DataShareHelper**. -Examples are given below. - ### Data Provider Application Development (Only for System Applications) -1. Import dependencies. +[DataShareExtensionAbility](../reference/apis/js-apis-application-dataShareExtensionAbility.md) provides the following APIs. You can override these APIs as required. + +- **onCreate** + + Called by the server to initialize service logic when the **DataShare** client connects to the **DataShareExtensionAbility** server. This method can be overridden as required. + +- **insert** + + Inserts data. This API is called when the client requests to insert data. + +- **update** + + Updates data. This API is called when the client requests to update data. + +- **delete** + + Deletes data. This API is called when the client requests to delete data. + +- **query** + + Queries data. This API is called when the client requests to query data. + +- **batchInsert** + + Batch inserts data. This API is called when the client requests to batch insert data. + +- **normalizeUri** + + Converts the URI provided by the client to the URI used by the server. + +- **denormalizeUri** + + Converts the URI used by the server to the initial URI passed by the client. + +Before implementing a **DataShare** service, you need to create a **DataShareExtensionAbility** object in the DevEco Studio project as follows: + +1. In the **ets** directory of the **Module** project, right-click and choose **New > Directory** to create a directory named **DataShareAbility**. + +2. Right-click the **DataShareAbility** directory, and choose **New > TypeScript File** to create a file named **DataShareAbility.ts**. + +3. In the **DataShareAbility.ts** file, import the **DataShareExtensionAbility** dependency package. You can override the service implementation as required. For example, if the data provider provides only the services for inserting, deleting, and querying data, you can override **insert()**, **delete()**, and **query()** only. + + +4. Import dependencies. ```ts import Extension from '@ohos.application.DataShareExtensionAbility'; @@ -47,9 +88,9 @@ Examples are given below. import dataSharePredicates from '@ohos.data.dataSharePredicates'; ``` -2. Override **DataShareExtensionAbility** APIs based on actual requirements. For example, if the data provider provides only data query, override only **query()**. +5. Override **DataShareExtensionAbility** APIs based on actual requirements. For example, if the data provider provides only data query, override only **query()**. -3. Implement the data provider services. For example, implement data storage of the data provider by using a database, reading and writing files, or accessing the network. +6. Implement the data provider services. For example, implement data storage of the data provider by using a database, reading and writing files, or accessing the network. ```ts const DB_NAME = "DB00.db"; @@ -57,29 +98,31 @@ Examples are given below. const DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS " + TBL_NAME + " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, isStudent BOOLEAN, Binary BINARY)"; - + let rdbStore; let result; - + export default class DataShareExtAbility extends Extension { private rdbStore_; - + // Override onCreate(). onCreate(want, callback) { - result = this.context.cacheDir + '/datashare.txt' + result = this.context.cacheDir + '/datashare.txt'; // Create an RDB store. - rdb.getRdbStore(this.context, { - name: DB_NAME, - securityLevel: rdb.SecurityLevel.S1 - }, function (err, data) { - rdbStore = data; - rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) { - console.log('DataShareExtAbility onCreate, executeSql done err:' + JSON.stringify(err)); + rdb.getRdbStore(this.context, { + name: DB_NAME, + securityLevel: rdb.SecurityLevel.S1 + }, function (err, data) { + rdbStore = data; + rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) { + console.log('DataShareExtAbility onCreate, executeSql done err:' + JSON.stringify(err)); }); - callback(); + if (callback) { + callback(); + } }); } - + // Override query(). query(uri, predicates, columns, callback) { if (predicates == null || predicates == undefined) { @@ -103,7 +146,7 @@ Examples are given below. }; ``` -4. Define **DataShareExtensionAbility** in **module.json5**. +7. Define **DataShareExtensionAbility** in **module.json5**. | Field| Description | | ------------ | ------------------------------------------------------------ | @@ -133,25 +176,25 @@ Examples are given below. 1. Import dependencies. ```ts - import Ability from '@ohos.application.Ability'; + import UIAbility from '@ohos.app.ability.UIAbility'; import dataShare from '@ohos.data.dataShare'; import dataSharePredicates from '@ohos.data.dataSharePredicates'; ``` - + 2. Define the URI string for communicating with the data provider. ```ts // Different from the URI defined in the module.json5 file, the URI passed in the parameter has an extra slash (/), because there is a DeviceID parameter between the second and the third slash (/). let dseUri = ("datashare:///com.samples.datasharetest.DataShare"); ``` - + 3. Create a **DataShareHelper** instance. ```ts let dsHelper; let abilityContext; - - export default class MainAbility extends Ability { + + export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage) { abilityContext = this.context; dataShare.createDataShareHelper(abilityContext, dseUri, (err, data)=>{ @@ -160,7 +203,7 @@ Examples are given below. } } ``` - + 4. Use the APIs provided by **DataShareHelper** to access the services provided by the provider, for example, adding, deleting, modifying, and querying data. ```ts @@ -168,7 +211,7 @@ Examples are given below. let valuesBucket = { "name": "ZhangSan", "age": 21, "isStudent": false, "Binary": new Uint8Array([1, 2, 3]) }; let updateBucket = { "name": "LiSi", "age": 18, "isStudent": true, "Binary": new Uint8Array([1, 2, 3]) }; let predicates = new dataSharePredicates.DataSharePredicates(); - let valArray = new Array("*"); + let valArray = ['*']; // Insert a piece of data. dsHelper.insert(dseUri, valuesBucket, (err, data) => { console.log("dsHelper insert result: " + data); @@ -183,7 +226,6 @@ Examples are given below. }); // Delete data. dsHelper.delete(dseUri, predicates, (err, data) => { - console.log("dsHelper delete result: " + data); + console.log("dsHelper delete result: " + data); }); ``` - diff --git a/en/application-dev/database/database-mdds-guidelines.md b/en/application-dev/database/database-mdds-guidelines.md index 0fc524a18d..1365e6c248 100644 --- a/en/application-dev/database/database-mdds-guidelines.md +++ b/en/application-dev/database/database-mdds-guidelines.md @@ -68,16 +68,16 @@ The following uses a single KV store as an example to describe the development p grantPermission(); // Stage model - import AbilityStage from '@ohos.application.Ability'; - + import UIAbility from '@ohos.app.ability.UIAbility'; + let context = null; - - class MainAbility extends AbilityStage { + + class EntryAbility extends UIAbility { onWindowStageCreate(windowStage) { let context = this.context; } } - + function grantPermission() { let permissions = ['ohos.permission.DISTRIBUTED_DATASYNC']; context.requestPermissionsFromUser(permissions).then((data) => { @@ -86,7 +86,7 @@ The following uses a single KV store as an example to describe the development p console.error('failed: ${error}'); }); } - + grantPermission(); ``` @@ -103,9 +103,9 @@ The following uses a single KV store as an example to describe the development p let context = featureAbility.getContext(); // Obtain the context of the stage model. - import AbilityStage from '@ohos.application.Ability'; + import UIAbility from '@ohos.app.ability.UIAbility'; let context = null; - class MainAbility extends AbilityStage{ + class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context; } @@ -119,7 +119,7 @@ The following uses a single KV store as an example to describe the development p } distributedKVStore.createKVManager(kvManagerConfig, function (err, manager) { if (err) { - console.error(`Failed to create KVManager. code is ${err.code},message is ${err.message}`); + console.error(`Failed to createKVManager.code is ${err.code},message is ${err.message}`); return; } console.log('Created KVManager successfully'); diff --git a/en/application-dev/database/database-preference-guidelines.md b/en/application-dev/database/database-preference-guidelines.md index 897be37128..a019101b7d 100644 --- a/en/application-dev/database/database-preference-guidelines.md +++ b/en/application-dev/database/database-preference-guidelines.md @@ -113,10 +113,10 @@ You can use the following APIs to delete a **Preferences** instance or data file ```ts // Obtain the context. - import Ability from '@ohos.application.Ability' + import UIAbility from '@ohos.app.ability.UIAbility' let context = null; let preferences = null; - export default class MainAbility extends Ability { + export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context; } @@ -159,7 +159,7 @@ You can use the following APIs to delete a **Preferences** instance or data file 5. Store data persistently. - Use **flush()** to flush data from the **Preferences** instance to its file. + Use **preferences.flush()** to flush data from the **Preferences** instance to its file. ```js preferences.flush(); @@ -186,7 +186,7 @@ You can use the following APIs to delete a **Preferences** instance or data file console.info("Failed to flush data. Cause: " + err); return; } - console.info("Flushed data successfully."); // The observer will be called. + console.info("Flushed data successfully."); // The observer will be called. }) }) ``` @@ -200,6 +200,6 @@ You can use the following APIs to delete a **Preferences** instance or data file proDelete.then(() => { console.info("Deleted data successfully."); }).catch((err) => { - console.info("Failed to delete data. Cause: " + err); + console.info("Failed to delete. Cause: " + err); }) ``` diff --git a/en/application-dev/reference/apis/js-apis-data-dataShare.md b/en/application-dev/reference/apis/js-apis-data-dataShare.md index f37b879ec9..4a7cc1ed50 100644 --- a/en/application-dev/reference/apis/js-apis-data-dataShare.md +++ b/en/application-dev/reference/apis/js-apis-data-dataShare.md @@ -175,7 +175,7 @@ Unsubscribes from the changes of the specified data. This API uses an asynchrono | -------- | -------------------- | ---- | ------------------------ | | type | string | Yes | Event type to unsubscribe from. The value is **dataChange**, which indicates data change events.| | uri | string | Yes | URI of the data.| -| callback | AsyncCallback<void> | No | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| +| callback | AsyncCallback<void> | No | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** diff --git a/en/application-dev/reference/apis/js-apis-data-distributedobject.md b/en/application-dev/reference/apis/js-apis-data-distributedobject.md index 130a128103..18b94e97c1 100644 --- a/en/application-dev/reference/apis/js-apis-data-distributedobject.md +++ b/en/application-dev/reference/apis/js-apis-data-distributedobject.md @@ -53,10 +53,10 @@ Stage model: ```ts // Import the module. import distributedObject from '@ohos.data.distributedDataObject'; -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; // Obtain the context. let context; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context } @@ -110,7 +110,7 @@ Called when the **revokeSave()** API is successfully called. ## DistributedObjectV9 -Provides APIs for managing a distributed data object. +Represents a distributed data object. ### setSessionId9+ @@ -156,10 +156,10 @@ Stage model: ```ts import distributedObject from '@ohos.data.distributedDataObject'; -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; // Obtain the context. let context; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context } @@ -218,10 +218,10 @@ Stage model: ```ts import distributedObject from '@ohos.data.distributedDataObject'; -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; // Obtain the context. let context; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context } @@ -257,7 +257,7 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo | Type| Description| | -------- | -------- | -| Promise<void> | Promise used to| +| Promise<void> | Promise that returns no value.| **Error codes** @@ -294,10 +294,10 @@ Stage model: ```ts import distributedObject from '@ohos.data.distributedDataObject'; -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; // Obtain the context. let context; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context } @@ -321,7 +321,7 @@ g_object.setSessionId().then (()=>{ on(type: 'change', callback: Callback<{ sessionId: string, fields: Array<string> }>): void -Subscribes to data changes of this distributed data object. +Subscribes to the data change of this distributed data object. **System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject @@ -357,10 +357,10 @@ Stage model: ```ts import distributedObject from '@ohos.data.distributedDataObject'; -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; // Obtain the context. let context; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context } @@ -381,7 +381,7 @@ g_object.on("change", globalThis.changeCallback); off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array<string> }>): void -Unsubscribes from the data changes of this distributed data object. +Unsubscribes from the data change of this distributed data object. **System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject @@ -413,10 +413,10 @@ Stage model: ```ts import distributedObject from '@ohos.data.distributedDataObject'; -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; // Obtain the context. let context; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context } @@ -432,7 +432,7 @@ g_object.off("change"); on(type: 'status', callback: Callback<{ sessionId: string, networkId: string, status: 'online' | 'offline' }>): void -Subscribes to statue changes of this distributed data object. +Subscribes to the status change of this distributed data object. **System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject @@ -463,10 +463,10 @@ Stage model: ```ts import distributedObject from '@ohos.data.distributedDataObject'; -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; // Obtain the context. let context; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context } @@ -507,7 +507,7 @@ let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:fals globalThis.statusCallback = (sessionId, networkId, status) => { globalThis.response += "status changed " + sessionId + " " + status + " " + networkId; } -// Unregister the specified status change callback. +// Unsubscribe from the specified status change callback for the distributed data object. g_object.off("status",globalThis.statusCallback); // Unregister all status change callbacks. g_object.off("status"); @@ -517,10 +517,10 @@ Stage model: ```ts import distributedObject from '@ohos.data.distributedDataObject'; -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; // Obtain the context. let context; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context } @@ -529,7 +529,7 @@ let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:fals globalThis.statusCallback = (sessionId, networkId, status) => { globalThis.response += "status changed " + sessionId + " " + status + " " + networkId; } -// Unregister the specified status change callback. +// Unsubscribe from all status change callbacks for the distributed data object. g_object.off("status",globalThis.statusCallback); // Unregister all status change callbacks. g_object.off("status"); @@ -579,10 +579,10 @@ g_object.save("local", (result) => { Stage model: ```ts import distributedObject from '@ohos.data.distributedDataObject'; -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; // Obtain the context. let context; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context } @@ -627,6 +627,8 @@ The saved data will be released in the following cases: **Example** +FA model: + ```js import distributedObject from '@ohos.data.distributedDataObject'; import featureAbility from '@ohos.ability.featureAbility'; @@ -643,13 +645,14 @@ g_object.save("local").then((result) => { console.error("save failed"); }); ``` +Stage model: ```js import distributedObject from '@ohos.data.distributedDataObject'; -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; // Obtain the context. let context; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context } @@ -712,10 +715,10 @@ Stage model: ```ts import distributedObject from '@ohos.data.distributedDataObject'; -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; // Obtain the context. let context; -class MainAbility extends Ability { +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage) { context = this.context } @@ -786,10 +789,10 @@ Stage model: ```ts import distributedObject from '@ohos.data.distributedDataObject'; -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; // Obtain the context. let context; -class MainAbility extends Ability { +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage) { context = this.context } @@ -1000,7 +1003,7 @@ Unsubscribes from the status change of this distributed data object. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| type | string | Yes| Event type to unsubscribe from. The value is **status**, which indicates the status change (online or offline) of the distributed data object.| +| type | string | Yes| Event type to unsubscribe from. The value is **status**, which indicates the status change (online or offline) of the distributed data object. | | callback | Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }> | No| Callback for status changes. If this parameter is not specified, all status change callbacks of this distributed data object will be unsubscribed from.
**sessionId** indicates the session ID of the distributed data object.
**deviceId** indicates the device ID of the distributed data object.
**status** indicates the object status, which can be online or offline.| diff --git a/en/application-dev/reference/apis/js-apis-data-preferences.md b/en/application-dev/reference/apis/js-apis-data-preferences.md index 5ba79b73ed..b51525e00e 100644 --- a/en/application-dev/reference/apis/js-apis-data-preferences.md +++ b/en/application-dev/reference/apis/js-apis-data-preferences.md @@ -38,7 +38,7 @@ Obtains a **Preferences** instance. This API uses an asynchronous callback to re | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | -| context | Context | Yes | Application context.
For the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For the application context of the stage model, see [Context](js-apis-ability-context.md). | +| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md). | | name | string | Yes | Name of the **Preferences** instance.| | callback | AsyncCallback<[Preferences](#preferences)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **object** is the **Preferences** instance obtained. Otherwise, **err** is an error code.| @@ -69,9 +69,9 @@ Stage model: ```ts // Obtain the context. -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; let context = null; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context; } @@ -103,7 +103,7 @@ Obtains a **Preferences** instance. This API uses a promise to return the result | Name | Type | Mandatory| Description | | ------- | ------------------------------------- | ---- | ----------------------- | -| context | Context | Yes | Application context.
For the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For the application context of the stage model, see [Context](js-apis-ability-context.md). | +| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md). | | name | string | Yes | Name of the **Preferences** instance.| **Return value** @@ -139,9 +139,9 @@ Stage model: ```ts // Obtain the context. -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; let context = null; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context; } @@ -177,7 +177,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi | Name | Type | Mandatory| Description | | -------- | ------------------------------------- | ---- | ---------------------------------------------------- | -| context | Context | Yes | Application context.
For the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For the application context of the stage model, see [Context](js-apis-ability-context.md). | +| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md). | | name | string | Yes | Name of the **Preferences** instance to delete. | | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.| @@ -215,9 +215,9 @@ Stage model: ```ts // Obtain the context. -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; let context = null; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context; } @@ -252,7 +252,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi | Name | Type | Mandatory| Description | | ------- | ------------------------------------- | ---- | ----------------------- | -| context | Context | Yes | Application context.
For the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For the application context of the stage model, see [Context](js-apis-ability-context.md). | +| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md). | | name | string | Yes | Name of the **Preferences** instance to delete.| **Return value** @@ -294,9 +294,9 @@ Stage model: ```ts // Obtain the context. -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; let context = null; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context; } @@ -328,7 +328,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi | Name | Type | Mandatory| Description | | -------- | ------------------------------------- | ---- | ---------------------------------------------------- | -| context | Context | Yes | Application context.
For the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For the application context of the stage model, see [Context](js-apis-ability-context.md). | +| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md). | | name | string | Yes | Name of the **Preferences** instance to remove. | | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.| @@ -358,9 +358,9 @@ Stage model: ```ts // Obtain the context. -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; let context = null; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context; } @@ -394,7 +394,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi | Name | Type | Mandatory| Description | | ------- | ------------------------------------- | ---- | ----------------------- | -| context | Context | Yes | Application context.
For the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For the application context of the stage model, see [Context](js-apis-ability-context.md). | +| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md). | | name | string | Yes | Name of the **Preferences** instance to remove.| **Return value** @@ -428,9 +428,9 @@ Stage model: ```ts // Obtain the context. -import Ability from '@ohos.application.Ability'; +import UIAbility from '@ohos.app.ability.UIAbility'; let context = null; -class MainAbility extends Ability{ +class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ context = this.context; } @@ -662,7 +662,7 @@ try { has(key: string, callback: AsyncCallback<boolean>): void -Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses an asynchronous callback to return the result.. +Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -698,7 +698,7 @@ try { has(key: string): Promise<boolean> -Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses a promise to return the result.. +Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -987,7 +987,7 @@ Unsubscribes from data changes. | Name | Type | Mandatory| Description | | -------- | -------------------------------- | ---- | ------------------------------------------ | | type | string | Yes | Event type to unsubscribe from. The value **change** indicates data change events. | -| callback | Callback<{ key : string }> | No | Callback to unregister. If this parameter is left blank, the callbacks used to subscribing to all data changes will be unregistered.| +| callback | Callback<{ key : string }> | No | Callback to unregister. If this parameter is left blank, all callbacks for data changes will be unregistered. | **Example** -- GitLab