harmony 鸿蒙@ohos.app.ability.ChildProcessArgs
@ohos.app.ability.ChildProcessArgs
The ChildProcessArgs module describes the parameters transferred to the child process. When starting a child process through childProcessManager, you can transfer parameters to the child process through ChildProcessArgs.
NOTE
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.
The APIs of this module can be used only in the stage model.
Modules to Import
import { ChildProcessArgs } from '@kit.AbilityKit';
Properties
System capability: SystemCapability.Ability.AbilityRuntime.Core
Name | Type | Mandatory | Description |
---|---|---|---|
entryParams | string | No | Custom parameters to be transparently transmit to the child process. The parameters can be obtained through args.entryParams in ChildProcess.onStart. The maximum data volume supported by entryParams is 150 KB. |
fds | Record |
No | 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. NOTE - fds supports a maximum of 16 groups. In each group, key contains a maximum of 20 characters. - The ID of a handle passed to the child process may change, but the handle always points to the same file. |
Example
For details about how to obtain the context in the example, see Obtaining the Context of UIAbility.
// In the main process:
import { common, ChildProcessArgs, childProcessManager } from '@kit.AbilityKit';
import { fileIo } from '@kit.CoreFileKit';
@Entry
@Component
struct Index {
build() {
Row() {
Column() {
Text('Click')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let path = context.filesDir + "/test.txt";
let file = fileIo.openSync(path, fileIo.OpenMode.READ_ONLY|fileIo.OpenMode.CREATE);
let args: ChildProcessArgs = {
entryParams: "testParam",
fds: {
"key1": file.fd
}
};
childProcessManager.startArkChildProcess("entry/./ets/process/DemoProcess.ets", args);
});
}
.width('100%')
}
.height('100%')
}
}
// In the child process:
import { ChildProcess, ChildProcessArgs } from '@kit.AbilityKit';
export default class DemoProcess extends ChildProcess {
onStart(args?: ChildProcessArgs) {
let entryParams = args?.entryParams;
let fd = args?.fds?.key1;
// ..
}
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙AbilityAccessControl
harmony 鸿蒙OH_NativeBundle_ApplicationInfo
harmony 鸿蒙OH_NativeBundle_ElementName
0
赞
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦