• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.ChildProcessArgs (Child Process Arguments)
2<!--Kit: Ability Kit-->
3<!--Subsystem: Ability-->
4<!--Owner: @SKY2001-->
5<!--Designer: @jsjzju-->
6<!--Tester: @lixueqing513-->
7<!--Adviser: @huipeizi-->
8
9The module describes the parameters transferred to the child process. When starting a child process through [childProcessManager](js-apis-app-ability-childProcessManager.md), you can transfer parameters to the child process through **ChildProcessArgs**.
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```ts
20import { ChildProcessArgs } from '@kit.AbilityKit';
21```
22
23## ChildProcessArgs
24
25**System capability**: SystemCapability.Ability.AbilityRuntime.Core
26
27| Name       | Type                   | Read-Only| Optional | Description                                                        |
28| ----------- | --------------------   | ---- | ------|------------------------------------------------------ |
29| entryParams | string                 |  No | Yes|Custom parameters to be transparently transmit to the child process. The parameters can be obtained through **args.entryParams** in [ChildProcess.onStart](js-apis-app-ability-childProcess.md#childprocessonstart). The maximum data volume supported by **entryParams** is 150 KB.|
30| fds         | Record<string, number> |  No | Yes|File Descriptor (FD) handles, which are used for communication between the main process and child process. They are passed to the child process in the form of key-value pairs, where **key** is a custom string and **value** is a DF handle. The FD handles can be obtained through **args.fds** in [ChildProcess.onStart](js-apis-app-ability-childProcess.md#childprocessonstart).<br><b>NOTE</b><br>- **fds** supports a maximum of 16 groups. In each group, **key** contains a maximum of 20 characters.<br>- The ID of a handle passed to the child process may change, but the handle always points to the same file.|
31
32**Example**
33
34For details about how to obtain the context in the example, see [Obtaining the Context of UIAbility](../../application-models/uiability-usage.md#obtaining-the-context-of-uiability).
35
36```ts
37// In the main process:
38import { common, ChildProcessArgs, childProcessManager } from '@kit.AbilityKit';
39import { fileIo } from '@kit.CoreFileKit';
40
41@Entry
42@Component
43struct Index {
44  build() {
45    Row() {
46      Column() {
47        Text('Click')
48          .fontSize(30)
49          .fontWeight(FontWeight.Bold)
50          .onClick(() => {
51            let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
52            let path = context.filesDir + "/test.txt";
53            let file = fileIo.openSync(path, fileIo.OpenMode.READ_ONLY | fileIo.OpenMode.CREATE);
54            let args: ChildProcessArgs = {
55              entryParams: "testParam",
56              fds: {
57                "key1": file.fd
58              }
59            };
60            childProcessManager.startArkChildProcess("entry/./ets/process/DemoProcess.ets", args);
61          });
62      }
63      .width('100%')
64    }
65    .height('100%')
66  }
67}
68```
69
70```ts
71// In the child process:
72import { ChildProcess, ChildProcessArgs } from '@kit.AbilityKit';
73
74export default class DemoProcess extends ChildProcess {
75
76  onStart(args?: ChildProcessArgs) {
77    let entryParams = args?.entryParams;
78    let fd = args?.fds?.key1;
79    // ..
80  }
81}
82```
83