• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.StartOptions (StartOptions) (System API)
2<!--Kit: Ability Kit-->
3<!--Subsystem: Ability-->
4<!--Owner: @dsz2025; @yangxuguang-huawei; @Luobniz21-->
5<!--Designer: @ccllee1-->
6<!--Tester: @lixueqing513-->
7<!--Adviser: @huipeizi-->
8
9StartOptions can be used as an input parameter for APIs used to launch a UIAbility (for example, [startAbility()](js-apis-inner-application-uiAbilityContext.md#startability-1)). It specifies the options for starting the target UIAbility, including but not limited to the window mode and the display where the target UIAbility is started.
10
11> **NOTE**
12>
13> The initial APIs of this module are supported since API version 9. 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> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.app.ability.StartOptions (StartOptions)](js-apis-app-ability-startOptions.md).
18
19## Modules to Import
20
21```ts
22import { StartOptions } from '@kit.AbilityKit';
23```
24
25## StartOptions
26
27**System capability**: SystemCapability.Ability.AbilityRuntime.Core
28
29**System API**: This is a system API.
30
31| Name| Type| Read-only| Optional| Description|
32| -------- | -------- | -------- | -------- | -------- |
33| windowFocused<sup>12+</sup> | boolean | No| Yes| Whether the window has focus. The default value is **true**, indicating that the window has focus.<br>**Constraints**:<br>1. This property takes effect only on 2-in-1 devices and tablets.<br>2. This property takes effect only in [UIAbilityContext.startAbility](js-apis-inner-application-uiAbilityContext.md#startability-1).|
34
35**Example**
36
37  ```ts
38  import { UIAbility, Want, StartOptions } from '@kit.AbilityKit';
39  import { BusinessError } from '@kit.BasicServicesKit';
40
41  export default class EntryAbility extends UIAbility {
42
43    onForeground() {
44      let want: Want = {
45        deviceId: '',
46        bundleName: 'com.example.myapplication',
47        abilityName: 'EntryAbility'
48      };
49      let options: StartOptions = {
50        displayId: 0
51      };
52
53      try {
54        this.context.startAbility(want, options, (err: BusinessError) => {
55          if (err.code) {
56            // Process service logic errors.
57            console.error(`startAbility failed, code is ${err.code}, message is ${err.message}`);
58            return;
59          }
60          // Carry out normal service processing.
61          console.info('startAbility succeed');
62        });
63      } catch (err) {
64        // Process input parameter errors.
65        let code = (err as BusinessError).code;
66        let message = (err as BusinessError).message;
67        console.error(`startAbility failed, code is ${code}, message is ${message}`);
68      }
69    }
70  }
71  ```
72