1# @ohos.app.appstartup.StartupTask 2 3The StartupTask module provides APIs related to startup tasks. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> The APIs of this module can be used only in the stage model. 10 11## Modules to Import 12 13```js 14import { StartupTask } from '@kit.AbilityKit'; 15``` 16 17## StartupTask.onDependencyCompleted 18 19onDependencyCompleted?(dependency: string, result: ESObject): void 20 21Called when the dependent startup task is complete. 22 23**System capability**: SystemCapability.Ability.AppStartup 24 25**Parameters** 26 27| Name | Type | Mandatory | Description | 28| -------- | -------- | -------- | -------- | 29| dependency | string | Yes | Name of the dependent startup task. | 30| result | Object | Yes | Execution result of the dependent startup task. | 31 32**Example** 33 34```ts 35import StartupTask from '@ohos.app.appstartup.StartupTask'; 36import common from '@ohos.app.ability.common'; 37import hilog from '@ohos.hilog'; 38 39@Sendable 40export default class StartupTask_001 extends StartupTask { 41 constructor() { 42 super(); 43 } 44 async init(context: common.AbilityStageContext) { 45 // ... 46 } 47 48 onDependencyCompleted(dependence: string, result: Object): void { 49 hilog.info(0x0000, 'testTag', 'StartupTask_001 onDependencyCompleted, dependence: %{public}s, result: %{public}s', 50 dependence, JSON.stringify(result)); 51 // ... 52 } 53} 54``` 55 56 57## StartupTask.init 58 59init(context: AbilityStageContext): Promise\<ESObject\> 60 61Initializes this startup task. 62 63**System capability**: SystemCapability.Ability.AppStartup 64 65**Parameters** 66 67| Name | Type | Mandatory | Description | 68| -------- | -------- | -------- | -------- | 69| context | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | Yes | Context of the ability stage. | 70 71**Return value** 72 73| Type | Description | 74| -------- | -------- | 75| Promise\<Object | void\> | Promise used to return the execution result. | 76 77**Example** 78 79```ts 80import { StartupTask, common } from '@kit.AbilityKit'; 81import { hilog } from '@kit.PerformanceAnalysisKit'; 82 83@Sendable 84export default class StartupTask_001 extends StartupTask { 85 constructor() { 86 super(); 87 } 88 async init(context: common.AbilityStageContext) { 89 hilog.info(0x0000, 'testTag', 'StartupTask_001 init.'); 90 // ... 91 92 return 'StartupTask_001'; 93 } 94 95 onDependencyCompleted(dependence: string, result: Object): void { 96 // ... 97 } 98} 99``` 100