diff --git a/en/application-dev/application-models/extensionability-overview.md b/en/application-dev/application-models/extensionability-overview.md index d85f02ace879e409a8d42d6f09408680a99f8056..8b3197383e17810cfee7c044611cf2286f4a987d 100644 --- a/en/application-dev/application-models/extensionability-overview.md +++ b/en/application-dev/application-models/extensionability-overview.md @@ -9,7 +9,7 @@ An [ExtensionAbilityType](../reference/apis/js-apis-bundleManager.md#extensionab - [FormExtensionAbility](../reference/apis/js-apis-app-form-formExtensionAbility.md): ExtensionAbility component of the form type, which provides APIs related to widgets. -- [WorkSchedulerExtensionAbility](../reference/apis/js-apis-resourceschedule-workScheduler.md): ExtensionAbility component of the work_scheduler type, which provides APIs for registering, canceling, and querying Work Scheduler tasks. +- [WorkSchedulerExtensionAbility](../reference/apis/js-apis-resourceschedule-workScheduler.md): ExtensionAbility component of the work_scheduler type, which provides callbacks for Work Scheduler tasks. - [InputMethodExtensionAbility](../reference/apis/js-apis-inputmethod.md): ExtensionAbility component of the input_method type, which provides an input method framework that can be used to hide the keyboard, obtain the list of installed input methods, display the dialog box for input method selection, and more. @@ -33,6 +33,7 @@ All types of ExtensionAbility components are started by the corresponding system The following uses [InputMethodExtensionAbility](../reference/apis/js-apis-inputmethod.md) as an example. As shown in the figure below, when an application calls the InputMethodExtensionAbility component, the input method management service is called first. The input method management service starts the InputMethodExtensionAbility component, returns the component to the application, and starts to manage its lifecycle. **Figure 1** Using the InputMethodExtensionAbility component + ![ExtensionAbility-start](figures/ExtensionAbility-start.png) @@ -48,11 +49,11 @@ You do not need to care when to add or delete a widget. The lifecycle of the For > **NOTE** > > For an application, all ExtensionAbility components of the same type run in an independent process, whereas UIAbility, ServiceExtensionAbility, and DataShareExtensionAbility run in another independent process. For details, see [Process Model (Stage Model)](process-model-stage.md). -> +> > For example, an application has one UIAbility component, one ServiceExtensionAbility, one DataShareExtensionAbility, two FormExtensionAbility, and one ImeExtensionAbility. When the application is running, there are three processes: -> +> > - UIAbility, ServiceExtensionAbility, and DataShareExtensionAbility run in an independent process. -> +> > - The two FormExtensionAbility components run in an independent process. -> +> > - The two ImeExtensionAbility components run in an independent process. diff --git a/en/application-dev/task-management/workscheduler-extensionability.md b/en/application-dev/task-management/workscheduler-extensionability.md index b2df1601a6608c6bb3c4dd10ce257a2c02284bc6..9b66adcd7401fff96804b5c020b5fd9e7f21f72f 100644 --- a/en/application-dev/task-management/workscheduler-extensionability.md +++ b/en/application-dev/task-management/workscheduler-extensionability.md @@ -44,7 +44,7 @@ To create a WorkScheduler project in DevEco Studio, perform the following steps: Import the module. ```ts - import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility' + import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility'; ``` Implement the lifecycle callbacks for the WorkSchedulerExtensionAbility. @@ -53,54 +53,54 @@ To create a WorkScheduler project in DevEco Studio, perform the following steps: export default class workAbility extends WorkSchedulerExtensionAbility { // Callback invoked when the Work Scheduler task starts. onWorkStart(workInfo) { - console.log(`onWorkStart CommonEvent publish start ${JSON.stringify(workInfo)}`) + console.log(`onWorkStart CommonEvent publish start ${JSON.stringify(workInfo)}`); // Publish an upgrade notification. - let notificationRequest = notification.getNotificationContentBasic('upgrade', upgradeMessage, '') + let notificationRequest = notification.getNotificationContentBasic('upgrade', upgradeMessage, ''); notification.publish(notificationRequest, (err) => { if (err) { - console.log(`onWorkStart notification publish err ${JSON.stringify(err)}`) + console.log(`onWorkStart notification publish err ${JSON.stringify(err)}`); } - console.log(`onWorkStart notification publish success`) - }) + console.log(`onWorkStart notification publish success`); + }); } // Callback invoked when the Work Scheduler task stops. onWorkStop(workInfo) { // Publish an upgrade completion notification. - let notificationRequest = notification.getNotificationContentBasic('upgrade', 'upgrade success', '') + let notificationRequest = notification.getNotificationContentBasic('upgrade', 'upgrade success', ''); notification.publish(notificationRequest, (err) => { if (err) { - console.log(`onWorkStop notification publish err ${JSON.stringify(err)}`) + console.log(`onWorkStop notification publish err ${JSON.stringify(err)}`); } - console.log(`onWorkStop notification publish success`) - }) + console.log(`onWorkStop notification publish success`); + }); } } ``` 3. In the **./entry/src/main/ets** directory under the **entry** module of the project, create a directory named **workAbility**. In the **workAbility** directory, create an ArkTS file named **WorkTest.ets** and implement the callbacks for Work Scheduler. -Import the module. + Import the module. - ```ts - import { workAbility } from '@ohos/library' - ``` + ```ts + import { workAbility } from '@ohos/library' + ``` -Inherit from **workAbility** and implement the lifecycle callbacks for the WorkSchedulerExtensionAbility. + Inherit from **workAbility** and implement the lifecycle callbacks for the WorkSchedulerExtensionAbility. - ```ts - export default class WorkTest extends workAbility { - onWorkStart(workInfo) { - console.log(`onWorkStartTest start ${JSON.stringify(workInfo)}`) - super.onWorkStart(workInfo) - } - + ```ts + export default class WorkTest extends workAbility { + onWorkStart(workInfo) { + console.log(`onWorkStartTest start ${JSON.stringify(workInfo)}`); + super.onWorkStart(workInfo); + } + onWorkStopTest(workInfo) { - super.onWorkStop(workInfo) - console.log(`onWorkStop value`) + super.onWorkStop(workInfo); + console.log(`onWorkStop value`); } } - ``` + ``` ### Implementing Work Scheduler @@ -109,11 +109,11 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS Import the module. ```ts - import workScheduler from '@ohos.resourceschedule.workScheduler' + import workScheduler from '@ohos.resourceschedule.workScheduler'; ``` Encapsulate the APIs for starting and stopping Work Scheduler tasks. - + ```ts export default class DelayWork { private workInfo = { @@ -124,25 +124,25 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS } // Start the Work Scheduler task. startWork(bundleName: string, abilityName: string) { - this.workInfo.bundleName = bundleName - this.workInfo.abilityName = abilityName + this.workInfo.bundleName = bundleName; + this.workInfo.abilityName = abilityName; try { - workScheduler.startWork(this.workInfo) - console.log(`startWork success`) + workScheduler.startWork(this.workInfo); + console.log(`startWork success`); } catch (error) { - Logger.error(TAG, `startWork startwork failed. code is ${error.code} message is ${error.message}`) + Logger.error(TAG, `startWork startwork failed. code is ${error.code} message is ${error.message}`); prompt.showToast({ message: `${error.message}` - }) + }); } } - + // Stop the Work Scheduler task. stopWork(bundleName: string, abilityName: string) { - this.workInfo.bundleName = bundleName - this.workInfo.abilityName = abilityName - workScheduler.stopWork(this.workInfo, false) - console.log(`stopWork`) + this.workInfo.bundleName = bundleName; + this.workInfo.abilityName = abilityName; + workScheduler.stopWork(this.workInfo, false); + console.log(`stopWork`); } } ``` @@ -152,45 +152,46 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS Import the module. ```ts - import { workAbility } from '@ohos/library' + import { workAbility } from '@ohos/library'; ``` Add the **Upgrade** button, which, when being clicked, will call the API encapsulated in **library** to start the Work Scheduler task. In the API, **bundleName** and **abilityName** are passed in, where the value of **abilityName** is **WorkTest**. - + ```ts Button($r('app.string.upgrade')) .width('60%') .height(40) .fontSize(30) .onClick(() => { - this.work.startWork('ohos.samples.workscheduler', 'WorkTest') - }) + this.work.startWork('ohos.samples.workscheduler', 'WorkTest'); + }); ``` When the component is destructed, it calls the API to stop the Work Scheduler task. - + ```ts aboutToDisappear() { - this.work.stopWork('ohos.samples.workscheduler', 'WorkTest') + this.work.stopWork('ohos.samples.workscheduler', 'WorkTest'); } ``` + ### Setting the Configuration File 1. Register the WorkSchedulerExtensionAbility in the [module.json5 file](../quick-start/module-configuration-file.md) under the **entry** module. Set **type** to **workScheduler** and **srcEntrance** to the code path of the WorkSchedulerExtensionAbility component. - ```json - { - "module": { - "extensionAbilities": [ - { - "name": "WorkTest", - "srcEntrance": "./ets/workAbility/WorkTest.ets", - "label": "$string:WorkSchedulerExtensionAbility_label", - "description": "$string:WorkSchedulerExtensionAbility_desc", - "type": "workScheduler" - } - ] - } - } - ``` + ```json + { + "module": { + "extensionAbilities": [ + { + "name": "WorkTest", + "srcEntrance": "./ets/workAbility/WorkTest.ets", + "label": "$string:WorkSchedulerExtensionAbility_label", + "description": "$string:WorkSchedulerExtensionAbility_desc", + "type": "workScheduler" + } + ] + } + } + ```