• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.StartOptions (StartOptions) (System API)
2
3**StartOptions** is used as an input parameter of [startAbility()](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability-1) to specify the window mode of an ability.
4
5> **NOTE**
6>
7> 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.
8>
9> The APIs of this module can be used only in the stage model.
10>
11> 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).
12
13## Modules to Import
14
15```ts
16import { StartOptions } from '@kit.AbilityKit';
17```
18
19## Properties
20
21**System capability**: SystemCapability.Ability.AbilityRuntime.Core
22
23**System API**: This is a system API.
24
25| Name| Type| Read-only| Optional| Description|
26| -------- | -------- | -------- | -------- | -------- |
27| 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#uiabilitycontextstartability-1).|
28
29**Example**
30
31  ```ts
32  import { UIAbility, Want, StartOptions } from '@kit.AbilityKit';
33  import { BusinessError } from '@kit.BasicServicesKit';
34
35  export default class EntryAbility extends UIAbility {
36
37    onForeground() {
38      let want: Want = {
39        deviceId: '',
40        bundleName: 'com.example.myapplication',
41        abilityName: 'EntryAbility'
42      };
43      let options: StartOptions = {
44        displayId: 0
45      };
46
47      try {
48        this.context.startAbility(want, options, (err: BusinessError) => {
49          if (err.code) {
50            // Process service logic errors.
51            console.error(`startAbility failed, code is ${err.code}, message is ${err.message}`);
52            return;
53          }
54          // Carry out normal service processing.
55          console.info('startAbility succeed');
56        });
57      } catch (err) {
58        // Process input parameter errors.
59        let code = (err as BusinessError).code;
60        let message = (err as BusinessError).message;
61        console.error(`startAbility failed, code is ${code}, message is ${message}`);
62      }
63    }
64  }
65  ```
66