• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# StartAbilityParameter
2
3The **StartAbilityParameter** module defines the parameters for starting an ability. The parameters can be used as input parameters in [startAbility](js-apis-ability-featureAbility.md#featureabilitystartability) to start the specified ability.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> The APIs of this module can be used only in the FA model.
9
10## Modules to Import
11
12```ts
13import ability from '@ohos.ability.ability';
14```
15
16## Attributes
17
18**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
19
20| Name              |   Type  | Mandatory  | Description                                   |
21| ------------------- | -------- | ---- | -------------------------------------- |
22| want                | [Want](js-apis-app-ability-want.md)|   Yes  | Want information about the target ability.                    |
23| abilityStartSetting | {[key: string]: any} | No   | Special attribute of the target ability. This attribute can be passed in the call.|
24| abilityStartSettings | Record\<string, Object> | No   | Special attribute of the target ability. This attribute can be passed in the call. You are advised to use this attribute to replace **abilityStartSetting**. When this attribute is set, **abilityStartSetting** does not take effect.|
25
26**Example**
27```ts
28import ability from '@ohos.ability.ability';
29import featureAbility from '@ohos.ability.featureAbility';
30import Want from '@ohos.app.ability.Want';
31
32let want: Want = {
33    bundleName: 'com.example.abilityStartSettingApp2',
34    abilityName: 'com.example.abilityStartSettingApp.EntryAbility',
35};
36
37let startAbilityParameter: ability.StartAbilityParameter = {
38    want : want,
39    abilityStartSettings : {
40        abilityBounds : [100,200,300,400],
41        windowMode :
42        featureAbility.AbilityWindowConfiguration.WINDOW_MODE_UNDEFINED,
43        displayId : 1,
44    }
45};
46
47try {
48    featureAbility.startAbility(startAbilityParameter, (error, data) => {
49        if (error && error.code !== 0) {
50            console.error(`startAbility fail, error: ${JSON.stringify(error)}`);
51        } else {
52            console.log(`startAbility success, data: ${JSON.stringify(data)}`);
53        }
54    });
55} catch(error) {
56    console.error(`startAbility error: ${JSON.stringify(error)}`);
57}
58```
59