• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.appstartup.StartupTask (Startup Task)
2<!--Kit: Ability Kit-->
3<!--Subsystem: Ability-->
4<!--Owner: @yzkp-->
5<!--Designer: @yzkp-->
6<!--Tester: @lixueqing513-->
7<!--Adviser: @huipeizi-->
8
9The module provides APIs related to startup tasks.
10
11> **NOTE**
12>
13> 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.
14>
15> The APIs of this module can be used only in the stage model.
16
17## Modules to Import
18
19```js
20import { StartupTask } from '@kit.AbilityKit';
21```
22
23## StartupTask
24
25Provides capabilities related to startup tasks. It is decorated by [@Sendable](../../arkts-utils/arkts-sendable.md#sendable-decorator).
26
27### onDependencyCompleted
28
29onDependencyCompleted?(dependency: string, result: Object): void
30
31Called when the dependent startup task is complete.
32
33**System capability**: SystemCapability.Ability.AppStartup
34
35**Parameters**
36
37| Name| Type| Mandatory| Description|
38| -------- | -------- | -------- | -------- |
39| dependency | string | Yes| Name of the dependent startup task.|
40| result | Object | Yes| Execution result of the dependent startup task.|
41
42**Example**
43
44```ts
45import { StartupTask, common } from '@kit.AbilityKit';
46import { hilog } from '@kit.PerformanceAnalysisKit';
47
48@Sendable
49export default class StartupTask_001 extends StartupTask {
50  constructor() {
51    super();
52  }
53
54  async init(context: common.AbilityStageContext) {
55    // ...
56  }
57
58  onDependencyCompleted(dependence: string, result: Object): void {
59    hilog.info(0x0000, 'testTag', 'StartupTask_001 onDependencyCompleted, dependence: %{public}s, result: %{public}s',
60      dependence, JSON.stringify(result));
61    // ...
62  }
63}
64```
65
66
67### init
68
69init(context: AbilityStageContext): Promise\<Object \| void\>
70
71Initializes this startup task.
72
73**System capability**: SystemCapability.Ability.AppStartup
74
75**Parameters**
76
77| Name| Type| Mandatory| Description|
78| -------- | -------- | -------- | -------- |
79| context | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | Yes| Context of the ability stage.|
80
81**Return value**
82
83| Type| Description|
84| -------- | -------- |
85| Promise\<Object \| void\> | Promise used to return the execution result.|
86
87**Example**
88
89```ts
90import { StartupTask, common } from '@kit.AbilityKit';
91import { hilog } from '@kit.PerformanceAnalysisKit';
92
93@Sendable
94export default class StartupTask_001 extends StartupTask {
95  constructor() {
96    super();
97  }
98  async init(context: common.AbilityStageContext) {
99    hilog.info(0x0000, 'testTag', 'StartupTask_001 init.');
100    // ...
101
102    return "StartupTask_001";
103  }
104
105  onDependencyCompleted(dependence: string, result: Object): void {
106    // ...
107  }
108}
109```
110