• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.AtomicServiceOptions (AtomicServiceOptions)
2
3**AtomicServiceOptions** is used as an input parameter of [openAtomicService()](js-apis-inner-application-uiAbilityContext.md#openatomicservice12) to carry arguments. It inherits from [StartOptions](js-apis-app-ability-startOptions.md).
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```ts
14import { AtomicServiceOptions } from '@kit.AbilityKit';
15```
16
17## AtomicServiceOptions
18
19**Atomic service API**: This API can be used in atomic services since API version 12.
20
21**System capability**: SystemCapability.Ability.AbilityRuntime.Core
22
23| Name| Type| Read Only| Optional| Description|
24| -------- | -------- | -------- | -------- | -------- |
25| [flags](js-apis-app-ability-wantConstant.md#flags) | number | No|  Yes| Mode in which the system processes the startup.<br>For example, **wantConstant.Flags.FLAG_INSTALL_ON_DEMAND** indicates that the installation-free capability is used.|
26| parameters | Record\<string, Object> | No|  Yes| Additional parameters. For details, see the **parameters** field in [Want](js-apis-app-ability-want.md).|
27
28**Example**
29
30```ts
31import { UIAbility, AtomicServiceOptions, common, wantConstant, bundleManager, CompletionHandler } from '@kit.AbilityKit';
32import { BusinessError } from '@kit.BasicServicesKit';
33
34export default class EntryAbility extends UIAbility {
35  onForeground() {
36    let appId: string = '6918661953712445909';
37    let completionHandler: CompletionHandler = {
38      onRequestSuccess: (elementName: bundleManager.ElementName, message: string): void => {
39        console.info(`${elementName.bundleName}-${elementName.moduleName}-${elementName.abilityName} start succeeded: ${message}`);
40      },
41      onRequestFailure: (elementName: bundleManager.ElementName, message: string): void => {
42        console.info(`${elementName.bundleName}-${elementName.moduleName}-${elementName.abilityName} start failed: ${message}`);
43      }
44    };
45
46    let options: AtomicServiceOptions = {
47      flags: wantConstant.Flags.FLAG_INSTALL_ON_DEMAND,
48      parameters: {
49        'demo.result': 123456
50      },
51      completionHandler: completionHandler
52    };
53
54    try {
55      this.context.openAtomicService(appId, options)
56        .then((result: common.AbilityResult) => {
57          // Carry out normal service processing.
58          console.info('openAtomicService succeed');
59        })
60        .catch((err: BusinessError) => {
61          // Process service logic errors.
62          console.error(`openAtomicService failed, code is ${err.code}, message is ${err.message}`);
63        });
64    } catch (err) {
65      // Process input parameter errors.
66      let code = (err as BusinessError).code;
67      let message = (err as BusinessError).message;
68      console.error(`openAtomicService failed, code is ${code}, message is ${message}`);
69    }
70  }
71}
72```
73