• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.ChildProcessOptions (Child Process Startup Options)
2<!--Kit: Ability Kit-->
3<!--Subsystem: Ability-->
4<!--Owner: @SKY2001-->
5<!--Designer: @jsjzju-->
6<!--Tester: @lixueqing513-->
7<!--Adviser: @huipeizi-->
8
9<!--Kit: Ability Kit-->
10<!--Subsystem: Ability-->
11<!--Owner: @SKY2001-->
12<!--Designer: @jsjzju-->
13<!--Tester: @lixueqing513-->
14
15The module describes the startup configuration of a child process. When starting a child process through [childProcessManager](js-apis-app-ability-childProcessManager.md), you can configure the startup configuration of the child process through **ChildProcessOptions**.
16
17> **NOTE**
18>
19> 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.
20>
21> The APIs of this module can be used only in the stage model.
22
23## Modules to Import
24
25```ts
26import { ChildProcessOptions } from '@kit.AbilityKit';
27```
28
29## ChildProcessOptions
30
31**System capability**: SystemCapability.Ability.AbilityRuntime.Core
32
33| Name       | Type     | Read-Only| Optional| Description                                                              |
34| ----------- | --------- | ---- | ----- | ----------------------------------------------- |
35| isolationMode | boolean | No| Yes| Controls the sandbox isolation level and network access permissions of the child process. **true** if the child process runs in an independent sandbox environment and cannot access the network; **false** if the child process shares the sandbox and network environment with the main process. The default value is **false**.|
36
37**Example**
38
39Sample code for the child process:
40
41```ts
42// Create the child process class DemoProcess.ets in src/main/ets/process of the entry module.
43// entry/src/main/ets/process/DemoProcess.ets
44import { ChildProcess, ChildProcessArgs } from '@kit.AbilityKit';
45
46export default class DemoProcess extends ChildProcess {
47  onStart(args?: ChildProcessArgs) {
48    let entryParams = args?.entryParams;
49    let fd = args?.fds?.key1;
50    // Child process code logic
51  }
52}
53```
54
55Sample code for the main process:
56
57```ts
58// Call childProcessManager.startArkChildProcess to start the child process.
59// entry/src/main/ets/pages/Index.ets
60import { ChildProcessArgs, ChildProcessOptions, childProcessManager } from '@kit.AbilityKit';
61import { BusinessError } from '@kit.BasicServicesKit';
62import DemoProcess from '../process/DemoProcess';
63
64@Entry
65@Component
66struct Index {
67  build() {
68    Row() {
69      Column() {
70        Text('Click')
71          .fontSize(30)
72          .fontWeight(FontWeight.Bold)
73          .onClick(() => {
74            try {
75              DemoProcess.toString(); // Call any API of the DemoProcess class to prevent the code from being directly optimized by the compiler because it is not being referenced.
76              let options: ChildProcessOptions = {
77                isolationMode: false
78              };
79              let args: ChildProcessArgs = {
80                entryParams: "testParam",
81              };
82              childProcessManager.startArkChildProcess("entry/ets/process/DemoProcess.ets", args, options)
83                .then((pid) => {
84                  console.info(`startChildProcess success, pid: ${pid}`);
85                })
86                .catch((err: BusinessError) => {
87                  console.error(`startChildProcess business error, errorCode: ${err.code}, errorMsg:${err.message}`);
88                });
89            } catch (err) {
90              console.error(`startChildProcess error, errorCode: ${err.code}, errorMsg:${err.message}`);
91            }
92          });
93      }
94      .width('100%')
95    }
96    .height('100%')
97  }
98}
99```
100