You need to sign in or sign up before continuing.
js-apis-ability-context.md 74.1 KB
Newer Older
1 2
# AbilityContext

Y
yuyaozhi 已提交
3 4
AbilityContext是Ability的上下文环境,继承自Context。

H
HuangXW 已提交
5
AbilityContext模块提供允许访问特定Ability的资源的能力,包括对Ability的启动、停止的设置、获取caller通信接口、拉起弹窗请求用户授权等。
Y
yuyaozhi 已提交
6

Y
yuyaozhi 已提交
7
> **说明:**
Z
zhangyafei.echo 已提交
8
>
H
HuangXW 已提交
9 10
>  - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>  - 本模块接口仅可在Stage模型下使用。
11

ahjxliubao2's avatar
ahjxliubao2 已提交
12 13
## 使用说明

R
RayShih 已提交
14 15
在使用AbilityContext的功能前,需要通过Ability子类实例获取。

Y
yuyaozhi 已提交
16
```js
H
HuangXW 已提交
17 18 19
import Ability from '@ohos.app.ability.Ability';

 let context = undefined;
ahjxliubao2's avatar
ahjxliubao2 已提交
20 21
class MainAbility extends Ability {
    onWindowStageCreate(windowStage) {
H
HuangXW 已提交
22
        context = this.context;
ahjxliubao2's avatar
ahjxliubao2 已提交
23 24 25 26
    }
}
```

27 28
## 属性

29 30
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core

G
guyuanzhang 已提交
31
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
32
| -------- | -------- | -------- | -------- | -------- |
G
guyuanzhang 已提交
33 34
| abilityInfo | AbilityInfo | 是 | 否 | Abilityinfo相关信息 |
| currentHapModuleInfo | HapModuleInfo | 是 | 否 | 当前hap包的信息 |
35
| config | [Configuration](js-apis-configuration.md) | 是 | 否 | 表示配置信息。 |
36

Y
yuyaozhi 已提交
37
## AbilityContext.startAbility
38

Y
yuyaozhi 已提交
39
startAbility(want: Want, callback: AsyncCallback<void>): void;
40

41
启动Ability(callback形式)。
42

Y
yuyaozhi 已提交
43
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
44

Y
yuyaozhi 已提交
45
**参数:**
ahjxliubao2's avatar
ahjxliubao2 已提交
46

G
guyuanzhang 已提交
47 48 49 50
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
| callback | AsyncCallback<void> | 是 | callback形式返回启动结果 |
51

H
HuangXW 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag.        |
| 16000011 | Context does not exist.        |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

Y
yuyaozhi 已提交
78 79 80
**示例:**

  ```js
81
  var want = {
H
HuangXW 已提交
82 83
    "bundleName": "com.example.myapp",
    "abilityName": "MyAbility"
84
  };
H
HuangXW 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

  try {
    this.context.startAbility(want, (error) => {
      if (error.code) {
        // 处理业务逻辑错误
        console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) +
          ' error.message: ' + JSON.stringify(error.message));
        return;
      }
      // 执行正常业务
      console.log('startAbility succeed');
    });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
102 103 104
  ```


Y
yuyaozhi 已提交
105
## AbilityContext.startAbility
106

Y
yuyaozhi 已提交
107
startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void;
ahjxliubao2's avatar
ahjxliubao2 已提交
108

109
启动Ability(callback形式)。
ahjxliubao2's avatar
ahjxliubao2 已提交
110

Y
yuyaozhi 已提交
111
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
112

Y
yuyaozhi 已提交
113
**参数:**
ahjxliubao2's avatar
ahjxliubao2 已提交
114

G
guyuanzhang 已提交
115 116 117
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md)  | 是 | 启动Ability的want信息。 |
X
xuzhihao 已提交
118
| options | [StartOptions](js-apis-application-StartOptions.md) | 是 | 启动Ability所携带的参数。 |
G
guyuanzhang 已提交
119
| callback | AsyncCallback<void> | 是 | callback形式返回启动结果。 |
ahjxliubao2's avatar
ahjxliubao2 已提交
120

H
HuangXW 已提交
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag.        |
| 16000011 | Context does not exist.        |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

Y
yuyaozhi 已提交
147
**示例:**
Z
zhangyafei.echo 已提交
148

Y
yuyaozhi 已提交
149
  ```js
ahjxliubao2's avatar
ahjxliubao2 已提交
150
  var want = {
H
HuangXW 已提交
151 152 153
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
ahjxliubao2's avatar
ahjxliubao2 已提交
154 155
  };
  var options = {
H
HuangXW 已提交
156
    windowMode: 0
ahjxliubao2's avatar
ahjxliubao2 已提交
157 158
  };

H
HuangXW 已提交
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
  try {
    this.context.startAbility(want, options, (error) => {
      if (error.code) {
        // 处理业务逻辑错误
        console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) +
          ' error.message: ' + JSON.stringify(error.message));
        return;
      }
      // 执行正常业务
      console.log('startAbility succeed');
    });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
  ```
ahjxliubao2's avatar
ahjxliubao2 已提交
176

Y
yuyaozhi 已提交
177
## AbilityContext.startAbility
ahjxliubao2's avatar
ahjxliubao2 已提交
178

Y
yuyaozhi 已提交
179
startAbility(want: Want, options?: StartOptions): Promise<void>;
180

181
启动Ability(promise形式)。
182

Y
yuyaozhi 已提交
183
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
184

Y
yuyaozhi 已提交
185
**参数:**
ahjxliubao2's avatar
ahjxliubao2 已提交
186

G
guyuanzhang 已提交
187 188 189
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
X
xuzhihao 已提交
190
| options | [StartOptions](js-apis-application-StartOptions.md) | 否 | 启动Ability所携带的参数。 |
191

Y
yuyaozhi 已提交
192 193
**返回值:**

G
guyuanzhang 已提交
194 195 196
| 类型 | 说明 |
| -------- | -------- |
| Promise<void> | Promise形式返回启动结果。 |
197

H
HuangXW 已提交
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag.        |
| 16000011 | Context does not exist.        |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

Y
yuyaozhi 已提交
224 225 226
**示例:**

  ```js
227
  var want = {
H
HuangXW 已提交
228 229
    "bundleName": "com.example.myapp",
    "abilityName": "MyAbility"
230
  };
ahjxliubao2's avatar
ahjxliubao2 已提交
231 232 233
  var options = {
  	windowMode: 0,
  };
H
HuangXW 已提交
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250

  try {
    this.context.startAbility(want, options)
      .then((data) => {
        // 执行正常业务
        console.log('startAbility succeed');
      })
      .catch((error) => {
        // 处理业务逻辑错误
        console.log('startAbility failed, error.code: ' + JSON.stringify(err.code) +
          ' error.message: ' + JSON.stringify(err.message));
      });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
251 252 253
  ```


Y
yuyaozhi 已提交
254
## AbilityContext.startAbilityForResult
255

256
startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>): void;
257

258
启动Ability并在结束的时候返回执行结果(callback形式)。
259

Y
yuyaozhi 已提交
260
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
261

Y
yuyaozhi 已提交
262
**参数:**
ahjxliubao2's avatar
ahjxliubao2 已提交
263

G
guyuanzhang 已提交
264 265 266 267
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
| callback | AsyncCallback<[AbilityResult](js-apis-featureAbility.md#abilityresult)> | 是 | 执行结果回调函数。 |
268

H
HuangXW 已提交
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag.        |
| 16000011 | Context does not exist.        |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
294

Y
yuyaozhi 已提交
295 296 297
**示例:**

  ```js
H
HuangXW 已提交
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };

  try {
    this.context.startAbilityForResult(want, (error, result) => {
      if (error.code) {
        // 处理业务逻辑错误
        console.log('startAbilityForResult failed, error.code: ' + JSON.stringify(error.code) +
          ' error.message: ' + JSON.stringify(error.message));
        return;
      }
      // 执行正常业务
      console.log("startAbilityForResult succeed, result.resultCode = " +
        result.resultCode)
    });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
321 322
  ```

Y
yuyaozhi 已提交
323
## AbilityContext.startAbilityForResult
ahjxliubao2's avatar
ahjxliubao2 已提交
324 325 326

startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback<AbilityResult>): void;

327
启动Ability并在结束的时候返回执行结果(callback形式)。
ahjxliubao2's avatar
ahjxliubao2 已提交
328

Y
yuyaozhi 已提交
329
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
330

Y
yuyaozhi 已提交
331
**参数:**
ahjxliubao2's avatar
ahjxliubao2 已提交
332

G
guyuanzhang 已提交
333 334 335
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
X
xuzhihao 已提交
336
| options | [StartOptions](js-apis-application-StartOptions.md) | 是 | 启动Ability所携带的参数。 |
G
guyuanzhang 已提交
337
| callback | AsyncCallback<[AbilityResult](js-apis-featureAbility.md#abilityresult)> | 是 | 执行结果回调函数。 |
ahjxliubao2's avatar
ahjxliubao2 已提交
338

H
HuangXW 已提交
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag.        |
| 16000011 | Context does not exist.        |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
ahjxliubao2's avatar
ahjxliubao2 已提交
364

Y
yuyaozhi 已提交
365 366 367
**示例:**

  ```js
H
HuangXW 已提交
368 369 370 371 372
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
ahjxliubao2's avatar
ahjxliubao2 已提交
373 374 375
  var options = {
    windowMode: 0,
  };
H
HuangXW 已提交
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393

  try {
    this.context.startAbilityForResult(want, options, (error, result) => {
      if (error.code) {
        // 处理业务逻辑错误
        console.log('startAbilityForResult failed, error.code: ' + JSON.stringify(error.code) +
          ' error.message: ' + JSON.stringify(error.message));
        return;
      }
      // 执行正常业务
      console.log("startAbilityForResult succeed, result.resultCode = " +
        result.resultCode)
    });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
ahjxliubao2's avatar
ahjxliubao2 已提交
394 395
  ```

396

Y
yuyaozhi 已提交
397
## AbilityContext.startAbilityForResult
398

Y
yuyaozhi 已提交
399
startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityResult>;
400

401
启动Ability并在结束的时候返回执行结果(promise形式)。
402

Y
yuyaozhi 已提交
403
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
404

Y
yuyaozhi 已提交
405
**参数:**
ahjxliubao2's avatar
ahjxliubao2 已提交
406

G
guyuanzhang 已提交
407 408 409
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
X
xuzhihao 已提交
410
| options | [StartOptions](js-apis-application-StartOptions.md) | 否 | 启动Ability所携带的参数。 |
ahjxliubao2's avatar
ahjxliubao2 已提交
411

412

Y
yuyaozhi 已提交
413 414
**返回值:**

G
guyuanzhang 已提交
415 416 417
| 类型 | 说明 |
| -------- | -------- |
| Promise<[AbilityResult](js-apis-featureAbility.md#abilityresult)> | Promise形式返回执行结果。 |
418

H
HuangXW 已提交
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag.        |
| 16000011 | Context does not exist.        |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

Y
yuyaozhi 已提交
445 446 447
**示例:**

  ```js
H
HuangXW 已提交
448 449 450 451
  var want = {
    "bundleName": "com.example.myapp",
    "abilityName": "MyAbility"
  };
ahjxliubao2's avatar
ahjxliubao2 已提交
452
  var options = {
H
HuangXW 已提交
453
  	windowMode: 0,
ahjxliubao2's avatar
ahjxliubao2 已提交
454
  };
H
HuangXW 已提交
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471

  try {
    this.context.startAbilityForResult(want, options)
      .then((result) => {
        // 执行正常业务
        console.log("startAbilityForResult succeed, result.resultCode = " + result.resultCode);
      })
      .catch((error) => {
        // 处理业务逻辑错误
        console.log('startAbilityForResult failed, error.code: ' + JSON.stringify(err.code) +
          ' error.message: ' + JSON.stringify(err.message));
      });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
472 473
  ```

474 475
## AbilityContext.startAbilityForResultWithAccount

Y
yuyaozhi 已提交
476
startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncCallback\<AbilityResult>): void;
477 478 479 480 481 482 483 484 485 486 487 488 489 490

启动一个Ability并在该Ability帐号销毁时返回执行结果(callback形式)。

**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
491
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。 |
492 493
| callback | AsyncCallback\<AbilityResult\> | 是 | 启动Ability的回调函数,返回Ability结果。 |

H
HuangXW 已提交
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag.        |
| 16000011 | Context does not exist.        |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

521 522 523 524 525 526 527 528 529
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
  var accountId = 100;
H
HuangXW 已提交
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547

  try {
    this.context.startAbilityForResultWithAccount(want, accountId, (error, result) => {
      if (error.code) {
        // 处理业务逻辑错误
        console.log('startAbilityForResultWithAccount failed, error.code: ' + JSON.stringify(error.code) +
          ' error.message: ' + JSON.stringify(error.message));
        return;
      }
      // 执行正常业务
      console.log("startAbilityForResultWithAccount succeed, result.resultCode = " +
        result.resultCode)
    });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
  ```


## AbilityContext.startAbilityForResultWithAccount

startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback\<void\>): void;

启动一个Ability并在该Ability帐号销毁时返回执行结果(callback形式)。

**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
568
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。 |
569 570 571
| options | [StartOptions](js-apis-application-StartOptions.md) | 是 | 启动Ability所携带的参数。 |
| callback | AsyncCallback\<void\> | 是 | 启动Ability的回调函数。 |

H
HuangXW 已提交
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag.        |
| 16000011 | Context does not exist.        |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

599 600 601 602 603 604 605 606 607 608
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
  var accountId = 100;
  var options = {
H
HuangXW 已提交
609
    windowMode: 0
610
  };
H
HuangXW 已提交
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628

  try {
    this.context.startAbilityForResultWithAccount(want, accountId, options, (error, result) => {
      if (error.code) {
        // 处理业务逻辑错误
        console.log('startAbilityForResultWithAccount failed, error.code: ' + JSON.stringify(error.code) +
          ' error.message: ' + JSON.stringify(error.message));
        return;
      }
      // 执行正常业务
      console.log("startAbilityForResultWithAccount succeed, result.resultCode = " +
        result.resultCode)
    });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
629 630 631
  ```


632
## AbilityContext.startAbilityForResultWithAccount
633 634 635

startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartOptions): Promise\<AbilityResult\>;

636
启动一个Ability并在该Ability帐号销毁时返回执行结果(promise形式)。
637 638 639 640 641 642 643 644 645 646 647 648

**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
649
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。 |
650 651 652 653 654 655 656 657
| options | [StartOptions](js-apis-application-StartOptions.md) | 否 | 启动Ability所携带的参数。 |

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;AbilityResult&gt; | 返回一个Promise,包含Ability结果。 |

H
HuangXW 已提交
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag.        |
| 16000011 | Context does not exist.        |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

685 686 687 688 689 690 691 692 693 694
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
  var accountId = 100;
  var options = {
H
HuangXW 已提交
695
    windowMode: 0
696
  };
H
HuangXW 已提交
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714

  try {
    this.context.startAbilityForResultWithAccount(want, accountId, options)
      .then((result) => {
        // 执行正常业务
        console.log("startAbilityForResultWithAccount succeed, result.resultCode = " +
          result.resultCode)
      })
      .catch((error) => {
        // 处理业务逻辑错误
        console.log('startAbilityForResultWithAccount failed, error.code: ' + JSON.stringify(err.code) +
          ' error.message: ' + JSON.stringify(err.message));
      });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
715
  ```
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
## AbilityContext.startServiceExtensionAbility

startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;

启动一个新的ServiceExtensionAbility(callback形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
| callback | AsyncCallback\<void\> | 是 | 启动Ability的回调函数。 |

H
HuangXW 已提交
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000011 | Context does not exist.        |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

752 753 754 755 756 757 758 759
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
H
HuangXW 已提交
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776

  try {
    this.context.startServiceExtensionAbility(want, (error) => {
      if (error.code) {
        // 处理业务逻辑错误
        console.log('startServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) +
          ' error.message: ' + JSON.stringify(error.message));
        return;
      }
      // 执行正常业务
      console.log('startServiceExtensionAbility succeed');
    });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794
  ```

## AbilityContext.startServiceExtensionAbility

startServiceExtensionAbility(want: Want): Promise\<void>;

启动一个新的ServiceExtensionAbility(Promise形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |

H
HuangXW 已提交
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000011 | Context does not exist.        |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

814 815 816 817 818 819 820 821
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
H
HuangXW 已提交
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838

  try {
    this.context.startServiceExtensionAbility(want)
      .then((data) => {
        // 执行正常业务
        console.log('startServiceExtensionAbility succeed');
      })
      .catch((error) => {
        // 处理业务逻辑错误
        console.log('startServiceExtensionAbility failed, error.code: ' + JSON.stringify(err.code) +
          ' error.message: ' + JSON.stringify(err.message));
      });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
839
  ```
H
HuangXW 已提交
840

841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
## AbilityContext.startServiceExtensionAbilityWithAccount

startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void>): void;

启动一个新的ServiceExtensionAbility(callback形式)。

**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
858
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。 |
859 860
| callback | AsyncCallback\<void\> | 是 | 启动Ability的回调函数。 |

H
HuangXW 已提交
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist.        |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

877 878 879 880 881 882 883 884 885
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
  var accountId = 100;
H
HuangXW 已提交
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902

  try {
    this.context.startServiceExtensionAbilityWithAccount(want, accountId, (error) => {
      if (error.code) {
        // 处理业务逻辑错误
        console.log('startServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) +
          ' error.message: ' + JSON.stringify(error.message));
        return;
      }
      // 执行正常业务
      console.log('startServiceExtensionAbilityWithAccount succeed');
    });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
  ```

## AbilityContext.startServiceExtensionAbilityWithAccount

startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<void>;

启动一个新的ServiceExtensionAbility(Promise形式)。

**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
922
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。 |
923

H
HuangXW 已提交
924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000011 | Context does not exist.        |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

944 945 946 947 948 949 950 951 952
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
  var accountId = 100;
H
HuangXW 已提交
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969

  try {
    this.context.startServiceExtensionAbilityWithAccount(want, accountId)
      .then((data) => {
        // 执行正常业务
        console.log('startServiceExtensionAbilityWithAccount succeed');
      })
      .catch((error) => {
        // 处理业务逻辑错误
        console.log('startServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(err.code) +
          ' error.message: ' + JSON.stringify(err.message));
      });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
970 971
  ```
## AbilityContext.stopServiceExtensionAbility
972

973 974 975 976 977 978 979 980 981 982 983 984 985 986 987
stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;

停止同一应用程序内的服务(callback形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
| callback | AsyncCallback\<void\> | 是 | 启动Ability的回调函数。 |

H
HuangXW 已提交
988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist.        |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

1004 1005 1006 1007 1008 1009 1010 1011
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
H
HuangXW 已提交
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028

  try {
    this.context.stopServiceExtensionAbility(want, (error) => {
      if (error.code) {
        // 处理业务逻辑错误
        console.log('stopServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) +
          ' error.message: ' + JSON.stringify(error.message));
        return;
      }
      // 执行正常业务
      console.log('stopServiceExtensionAbility succeed');
    });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
  ```

## AbilityContext.stopServiceExtensionAbility

stopServiceExtensionAbility(want: Want): Promise\<void>;

停止同一应用程序内的服务(Promise形式)。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |

H
HuangXW 已提交
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist.        |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

1063 1064 1065 1066 1067 1068 1069 1070
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
H
HuangXW 已提交
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087

  try {
    this.context.stopServiceExtensionAbility(want)
      .then((data) => {
        // 执行正常业务
        console.log('stopServiceExtensionAbility succeed');
      })
      .catch((error) => {
        // 处理业务逻辑错误
        console.log('stopServiceExtensionAbility failed, error.code: ' + JSON.stringify(err.code) +
          ' error.message: ' + JSON.stringify(err.message));
      });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
  ```

## AbilityContext.stopServiceExtensionAbilityWithAccount

stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void>): void;

使用帐户停止同一应用程序内的服务(callback形式)。

**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
1107
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。 |
1108 1109
| callback | AsyncCallback\<void\> | 是 | 启动Ability的回调函数。 |

H
HuangXW 已提交
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist.        |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

1127 1128 1129 1130 1131 1132 1133 1134 1135
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
  var accountId = 100;
H
HuangXW 已提交
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152

  try {
    this.context.stopServiceExtensionAbilityWithAccount(want, accountId, (error) => {
      if (error.code) {
        // 处理业务逻辑错误
        console.log('stopServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) +
          ' error.message: ' + JSON.stringify(error.message));
        return;
      }
      // 执行正常业务
      console.log('stopServiceExtensionAbilityWithAccount succeed');
    });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171
  ```

## AbilityContext.stopServiceExtensionAbilityWithAccount

stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<void>;

使用帐户停止同一应用程序内的服务(Promise形式)。

**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
1172
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。 |
1173

H
HuangXW 已提交
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist.        |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

1191 1192 1193 1194 1195 1196 1197 1198 1199
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
  var accountId = 100;
H
HuangXW 已提交
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216

  try {
    this.context.stopServiceExtensionAbilityWithAccount(want, accountId)
      .then((data) => {
        // 执行正常业务
        console.log('stopServiceExtensionAbilityWithAccount succeed');
      })
      .catch((error) => {
        // 处理业务逻辑错误
        console.log('stopServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(err.code) +
          ' error.message: ' + JSON.stringify(err.message));
      });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
1217
  ```
1218

Y
yuyaozhi 已提交
1219
## AbilityContext.terminateSelf
1220

1221
terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
1222

1223
停止Ability自身(callback形式)。
1224

Y
yuyaozhi 已提交
1225
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
1226

Y
yuyaozhi 已提交
1227
**参数:**
ahjxliubao2's avatar
ahjxliubao2 已提交
1228

G
guyuanzhang 已提交
1229 1230 1231
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,返回接口调用是否成功的结果。 |
1232

H
HuangXW 已提交
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist.        |
| 16000050 | Internal Error. |

Y
yuyaozhi 已提交
1246 1247 1248
**示例:**

  ```js
H
HuangXW 已提交
1249 1250 1251 1252 1253 1254 1255 1256 1257
  this.context.terminateSelf((error) => {
    if (error.code) {
      // 处理业务逻辑错误
      console.log('terminateSelf failed, error.code: ' + JSON.stringify(error.code) +
        ' error.message: ' + JSON.stringify(error.message));
      return;
    }
    // 执行正常业务
    console.log('terminateSelf succeed');
ahjxliubao2's avatar
ahjxliubao2 已提交
1258
  });
1259 1260 1261
  ```


Y
yuyaozhi 已提交
1262
## AbilityContext.terminateSelf
1263

1264
terminateSelf(): Promise&lt;void&gt;;
1265

1266
停止Ability自身(promise形式)。
1267

Y
yuyaozhi 已提交
1268
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
1269

Y
yuyaozhi 已提交
1270
**返回值:**
ahjxliubao2's avatar
ahjxliubao2 已提交
1271

G
guyuanzhang 已提交
1272 1273 1274
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 返回一个Promise,包含接口的结果。 |
1275

H
HuangXW 已提交
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist.        |
| 16000050 | Internal Error. |

Y
yuyaozhi 已提交
1289 1290 1291
**示例:**

  ```js
H
HuangXW 已提交
1292 1293 1294
  this.context.terminateSelf().then((data) => {
    // 执行正常业务
    console.log('terminateSelf succeed');
ahjxliubao2's avatar
ahjxliubao2 已提交
1295
  }).catch((error) => {
H
HuangXW 已提交
1296 1297 1298
    // 处理业务逻辑错误
    console.log('terminateSelf failed, error.code: ' + JSON.stringify(error.code) +
      ' error.message: ' + JSON.stringify(error.message));
1299 1300 1301 1302
  });
  ```


Y
yuyaozhi 已提交
1303
## AbilityContext.terminateSelfWithResult
1304

1305
terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;void&gt;): void;
1306

1307
停止Ability,配合startAbilityForResult使用,返回给接口调用方AbilityResult信息(callback形式)。
1308

Y
yuyaozhi 已提交
1309
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
1310

Y
yuyaozhi 已提交
1311
**参数:**
ahjxliubao2's avatar
ahjxliubao2 已提交
1312

G
guyuanzhang 已提交
1313 1314 1315 1316
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | 是 | 返回给调用startAbilityForResult&nbsp;接口调用方的相关信息。 |
| callback | AsyncCallback&lt;void&gt; | 是 | callback形式返回停止结果。 |
1317

Y
yuyaozhi 已提交
1318 1319 1320
**示例:**

  ```js
1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331
  var want = {
    "bundleName": "com.extreme.myapplication",
    "abilityName": "SecondAbility"
  }
  var resultCode = 100;
  // 返回给接口调用方AbilityResult信息
  var abilityResult = {
    want,
    resultCode
  }
  this.context.terminateSelfWithResult(abilityResult, (error) => {
1332 1333 1334 1335 1336 1337
          console.log("terminateSelfWithResult is called = " + error.code)
      }
  );
  ```


Y
yuyaozhi 已提交
1338
## AbilityContext.terminateSelfWithResult
1339

1340
terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;;
1341

1342
停止Ability,配合startAbilityForResult使用,返回给接口调用方AbilityResult信息(promise形式)。
1343

Y
yuyaozhi 已提交
1344
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
1345

Y
yuyaozhi 已提交
1346
**参数:**
ahjxliubao2's avatar
ahjxliubao2 已提交
1347

G
guyuanzhang 已提交
1348 1349 1350
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | 是 | 返回给startAbilityForResult&nbsp;调用方的信息。 |
1351

Y
yuyaozhi 已提交
1352 1353
**返回值:**

G
guyuanzhang 已提交
1354 1355 1356
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | promise形式返回停止结果。 |
1357

Y
yuyaozhi 已提交
1358 1359 1360
**示例:**

  ```js
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371
  var want = {
    "bundleName": "com.extreme.myapplication",
    "abilityName": "SecondAbility"
  }
  var resultCode = 100;
  // 返回给接口调用方AbilityResult信息
  var abilityResult = {
    want,
    resultCode
  }
  this.context.terminateSelfWithResult(abilityResult).then((result) => {
1372 1373 1374 1375
      console.log("terminateSelfWithResult")
  }
  )
  ```
ahjxliubao2's avatar
ahjxliubao2 已提交
1376

H
HuangXW 已提交
1377
## AbilityContext.connectServiceExtensionAbility
1378

H
HuangXW 已提交
1379
connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
1380

1381
使用AbilityInfo.AbilityType.SERVICE模板将当前Ability连接到一个Ability。
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
| options | [ConnectOptions](js-apis-featureAbility.md#connectoptions) | 否 | 远端对象实例。 |

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| number | 返回Ability连接的结果code。 |

H
HuangXW 已提交
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000011 | Context does not exist.        |
| 16000050 | Internal Error. |

1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
  var options = {
    onConnect(elementName, remote) { console.log('----------- onConnect -----------') },
    onDisconnect(elementName) { console.log('----------- onDisconnect -----------') },
    onFailed(code) { console.log('----------- onFailed -----------') }
  }
H
HuangXW 已提交
1427 1428 1429 1430 1431 1432 1433 1434 1435

  var connection = null;
  try {
    connection = this.context.connectServiceExtensionAbility(want, options);
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
1436 1437 1438
  ```


H
HuangXW 已提交
1439
## AbilityContext.connectServiceExtensionAbilityWithAccount
1440

H
HuangXW 已提交
1441
connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions): number;
1442

1443
使用AbilityInfo.AbilityType.SERVICE模板和account将当前Ability连接到一个Ability。
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455

**需要权限:** ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
1456
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。 |
1457 1458 1459 1460 1461 1462 1463 1464
| options | [ConnectOptions](js-apis-featureAbility.md#connectoptions) | 否 | 远端对象实例。 |

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| number | 返回Ability连接的结果code。 |

H
HuangXW 已提交
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000006 | Can not cross user operations. |
| 16000011 | Context does not exist.        |
| 16000050 | Internal Error. |

1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
  var accountId = 100;
  var options = {
    onConnect(elementName, remote) { console.log('----------- onConnect -----------') },
    onDisconnect(elementName) { console.log('----------- onDisconnect -----------') },
    onFailed(code) { console.log('----------- onFailed -----------') }
  }
H
HuangXW 已提交
1494 1495 1496 1497 1498 1499 1500 1501 1502

  var connection = null;
  try {
    connection = this.context.connectServiceExtensionAbilityWithAccount(want, accountId, options);
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
1503 1504
  ```

H
HuangXW 已提交
1505
## AbilityContext.disconnectServiceExtensionAbility
1506

H
HuangXW 已提交
1507
disconnectServiceExtensionAbility(connection: number): Promise\<void>;
1508

1509
断开连接(promise形式)。
1510 1511 1512 1513 1514 1515 1516 1517 1518

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
1519
| connection | number | 是 | 连接的Ability的数字代码。 |
1520 1521 1522 1523 1524 1525 1526

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise\<void> | 返回执行结果。 |

H
HuangXW 已提交
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000003 | Input error. The specified id does not exist. |
| 16000011 | Context does not exist.        |
| 16000050 | Internal Error. |

1540
**示例:**
Z
zhangyafei.echo 已提交
1541

1542
  ```js
H
HuangXW 已提交
1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561
  // connection为connectAbility中的返回值
  var connection = 1;

  try {
    this.context.disconnectServiceExtensionAbility(connection)
      .then((data) => {
        // 执行正常业务
        console.log('disconnectServiceExtensionAbility succeed');
      })
      .catch((error) => {
        // 处理业务逻辑错误
        console.log('disconnectServiceExtensionAbility failed, error.code: ' + JSON.stringify(err.code) +
          ' error.message: ' + JSON.stringify(err.message));
      });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
1562 1563
  ```

H
HuangXW 已提交
1564
## AbilityContext.disconnectServiceExtensionAbility
1565

H
HuangXW 已提交
1566
disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback\<void>): void;
1567

1568
断开连接(callback形式)。
1569 1570 1571 1572 1573 1574 1575 1576 1577

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
1578
| connection | number | 是 | 连接的Ability的数字代码。 |
1579 1580
| callback | AsyncCallback\<void> | 是 | 表示指定的回调方法。 |

H
HuangXW 已提交
1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000003 | Input error. The specified id does not exist. |
| 16000011 | Context does not exist.        |
| 16000050 | Internal Error. |

1594 1595 1596
**示例:**

  ```js
H
HuangXW 已提交
1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609
  // connection为connectServiceExtensionAbility中的返回值
  var connection = 1;

  try {
    this.context.disconnectServiceExtensionAbility(connection, (error) => {
      if (error.code) {
        // 处理业务逻辑错误
        console.log('disconnectServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) +
          ' error.message: ' + JSON.stringify(error.message));
        return;
      }
      // 执行正常业务
      console.log('disconnectServiceExtensionAbility succeed');
1610
    });
H
HuangXW 已提交
1611 1612 1613 1614 1615
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
1616
  ```
ahjxliubao2's avatar
ahjxliubao2 已提交
1617

Y
yuyaozhi 已提交
1618
## AbilityContext.startAbilityByCall
ahjxliubao2's avatar
ahjxliubao2 已提交
1619 1620 1621

startAbilityByCall(want: Want): Promise&lt;Caller&gt;;

1622
启动指定Ability至前台或后台,同时获取其Caller通信接口,调用方可使用Caller与被启动的Ability进行通信。
ahjxliubao2's avatar
ahjxliubao2 已提交
1623

Y
yuyaozhi 已提交
1624
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
1625

Y
yuyaozhi 已提交
1626
**参数:**
ahjxliubao2's avatar
ahjxliubao2 已提交
1627

G
guyuanzhang 已提交
1628 1629
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
1630
| want | [Want](js-apis-application-Want.md) | 是 | 传入需要启动的Ability的信息,包含abilityName、moduleName、bundleName、deviceId(可选)、parameters(可选),其中deviceId缺省或为空表示启动本地Ability,parameters缺省或为空表示后台启动Ability。 |
ahjxliubao2's avatar
ahjxliubao2 已提交
1631

Y
yuyaozhi 已提交
1632 1633
**返回值:**

G
guyuanzhang 已提交
1634 1635 1636
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;Caller&gt; | 获取要通讯的caller对象。 |
ahjxliubao2's avatar
ahjxliubao2 已提交
1637

Y
yuyaozhi 已提交
1638
**示例:**
Z
zhangyafei.echo 已提交
1639

Y
yuyaozhi 已提交
1640
  ```js
H
HuangXW 已提交
1641
  var caller = undefined;
1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665

  // 后台启动Ability,不配置parameters
  var wantBackground = {
      bundleName: "com.example.myservice",
      moduleName: "entry",
      abilityName: "MainAbility",
      deviceId: ""
  };
  this.context.startAbilityByCall(wantBackground)
    .then((obj) => {
        caller = obj;
        console.log('GetCaller success');
    }).catch((error) => {
        console.log(`GetCaller failed with ${error}`);
    });

  // 前台启动Ability,将parameters中的"ohos.aafwk.param.callAbilityToForeground"配置为true
  var wantForeground = {
      bundleName: "com.example.myservice",
      moduleName: "entry",
      abilityName: "MainAbility",
      deviceId: "",
      parameters: {
        "ohos.aafwk.param.callAbilityToForeground": true
ahjxliubao2's avatar
ahjxliubao2 已提交
1666
      }
1667 1668 1669 1670 1671 1672 1673 1674
  };
  this.context.startAbilityByCall(wantForeground)
    .then((obj) => {
        caller = obj;
        console.log('GetCaller success');
    }).catch((error) => {
        console.log(`GetCaller failed with ${error}`);
    });
ahjxliubao2's avatar
ahjxliubao2 已提交
1675 1676
  ```

1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693
## AbilityContext.startAbilityWithAccount

startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void\>): void;

根据account启动Ability(callback形式)。

**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
1694
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。 |
1695 1696
| callback | AsyncCallback\<void\> | 是 | 启动Ability的回调函数。 |

H
HuangXW 已提交
1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag.        |
| 16000011 | Context does not exist.        |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

1724 1725 1726 1727 1728 1729 1730 1731 1732
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
  var accountId = 100;
H
HuangXW 已提交
1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749

  try {
    this.context.startAbilityWithAccount(want, accountId, (error) => {
      if (error.code) {
        // 处理业务逻辑错误
        console.log('startAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) +
          ' error.message: ' + JSON.stringify(error.message));
        return;
      }
      // 执行正常业务
      console.log('startAbilityWithAccount succeed');
    });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769
  ```


## AbilityContext.startAbilityWithAccount

startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback\<void\>): void;

根据account启动Ability(callback形式)。

**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
1770
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。|
1771 1772 1773
| options | [StartOptions](js-apis-application-StartOptions.md) | 否 | 启动Ability所携带的参数。 |
| callback | AsyncCallback\<void\> | 是 | 启动Ability的回调函数。 |

H
HuangXW 已提交
1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag.        |
| 16000011 | Context does not exist.        |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

1801 1802 1803 1804 1805 1806 1807 1808 1809 1810
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
  var accountId = 100;
  var options = {
H
HuangXW 已提交
1811
    windowMode: 0
1812
  };
H
HuangXW 已提交
1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829

  try {
    this.context.startAbilityWithAccount(want, accountId, options, (error) => {
      if (error.code) {
        // 处理业务逻辑错误
        console.log('startAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) +
          ' error.message: ' + JSON.stringify(error.message));
        return;
      }
      // 执行正常业务
      console.log('startAbilityWithAccount succeed');
    });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849
  ```


## AbilityContext.startAbilityWithAccount

startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): Promise\<void\>;

根据account启动Ability(Promise形式)。

**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | 是 | 启动Ability的want信息。 |
1850
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。 |
1851 1852
| options | [StartOptions](js-apis-application-StartOptions.md) | 否 | 启动Ability所携带的参数。 |

H
HuangXW 已提交
1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879
**错误码:**

以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)

| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag.        |
| 16000011 | Context does not exist.        |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |

1880 1881 1882 1883 1884 1885 1886 1887 1888 1889
**示例:**

  ```js
  var want = {
    "deviceId": "",
    "bundleName": "com.extreme.test",
    "abilityName": "MainAbility"
  };
  var accountId = 100;
  var options = {
H
HuangXW 已提交
1890
    windowMode: 0
1891
  };
H
HuangXW 已提交
1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908

  try {
    this.context.startAbilityWithAccount(want, accountId, options)
      .then((data) => {
        // 执行正常业务
        console.log('startAbilityWithAccount succeed');
      })
      .catch((error) => {
        // 处理业务逻辑错误
        console.log('startAbilityWithAccount failed, error.code: ' + JSON.stringify(err.code) +
          ' error.message: ' + JSON.stringify(err.message));
      });
  } catch (paramError) {
    // 处理入参错误异常
    console.log('error.code: ' + JSON.stringify(paramError.code) +
      ' error.message: ' + JSON.stringify(paramError.message));
  }
1909
  ```
ahjxliubao2's avatar
ahjxliubao2 已提交
1910

Y
yuyaozhi 已提交
1911
## AbilityContext.requestPermissionsFromUser
ahjxliubao2's avatar
ahjxliubao2 已提交
1912 1913 1914

requestPermissionsFromUser(permissions: Array&lt;string&gt;, requestCallback: AsyncCallback&lt;PermissionRequestResult&gt;) : void;

1915
拉起弹窗请求用户授权(callback形式)。
ahjxliubao2's avatar
ahjxliubao2 已提交
1916

Y
yuyaozhi 已提交
1917
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
1918

Y
yuyaozhi 已提交
1919
**参数:**
ahjxliubao2's avatar
ahjxliubao2 已提交
1920

G
guyuanzhang 已提交
1921 1922 1923 1924
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | 是 | 权限列表。 |
| callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | 是 | 回调函数,返回接口调用是否成功的结果。 |
ahjxliubao2's avatar
ahjxliubao2 已提交
1925

Y
yuyaozhi 已提交
1926
**示例:**
Z
zhangyafei.echo 已提交
1927

Y
yuyaozhi 已提交
1928 1929 1930 1931
  ```js
       var permissions=['com.example.permission']
       this.context.requestPermissionsFromUser(permissions,(result) => {
       console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
ahjxliubao2's avatar
ahjxliubao2 已提交
1932
  });
Z
zhangyafei.echo 已提交
1933

ahjxliubao2's avatar
ahjxliubao2 已提交
1934 1935 1936
  ```


Y
yuyaozhi 已提交
1937
## AbilityContext.requestPermissionsFromUser
ahjxliubao2's avatar
ahjxliubao2 已提交
1938 1939 1940

requestPermissionsFromUser(permissions: Array&lt;string&gt;) : Promise&lt;PermissionRequestResult&gt;;

1941
拉起弹窗请求用户授权(promise形式)。
ahjxliubao2's avatar
ahjxliubao2 已提交
1942

Y
yuyaozhi 已提交
1943
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
1944

Y
yuyaozhi 已提交
1945
**参数:**
ahjxliubao2's avatar
ahjxliubao2 已提交
1946

G
guyuanzhang 已提交
1947 1948 1949
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | 是 | 权限列表。 |
Y
yuyaozhi 已提交
1950 1951

**返回值:**
ahjxliubao2's avatar
ahjxliubao2 已提交
1952

G
guyuanzhang 已提交
1953 1954 1955
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | 返回一个Promise,包含接口的结果。 |
ahjxliubao2's avatar
ahjxliubao2 已提交
1956

Y
yuyaozhi 已提交
1957
**示例:**
Z
zhangyafei.echo 已提交
1958

Y
yuyaozhi 已提交
1959 1960 1961
  ```js
   var permissions=['com.example.permission']
       this.context.requestPermissionsFromUser(permissions).then((data) => {
R
RayShih 已提交
1962
      console.log('success:' + JSON.stringify(data));
ahjxliubao2's avatar
ahjxliubao2 已提交
1963
  }).catch((error) => {
R
RayShih 已提交
1964
      console.log('failed:' + JSON.stringify(error));
ahjxliubao2's avatar
ahjxliubao2 已提交
1965
  });
Y
yuyaozhi 已提交
1966

ahjxliubao2's avatar
ahjxliubao2 已提交
1967 1968 1969
  ```


Y
yuyaozhi 已提交
1970
## AbilityContext.setMissionLabel
ahjxliubao2's avatar
ahjxliubao2 已提交
1971 1972 1973

setMissionLabel(label: string, callback:AsyncCallback&lt;void&gt;): void;

1974
设置ability在任务中显示的名称(callback形式)。
ahjxliubao2's avatar
ahjxliubao2 已提交
1975

Y
yuyaozhi 已提交
1976
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
1977

Y
yuyaozhi 已提交
1978
**参数:**
ahjxliubao2's avatar
ahjxliubao2 已提交
1979

G
guyuanzhang 已提交
1980 1981 1982 1983
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| label | string | 是 | 显示名称。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,返回接口调用是否成功的结果。 |
ahjxliubao2's avatar
ahjxliubao2 已提交
1984

Y
yuyaozhi 已提交
1985
**示例:**
Z
zhangyafei.echo 已提交
1986

Y
yuyaozhi 已提交
1987
  ```js
ahjxliubao2's avatar
ahjxliubao2 已提交
1988
  this.context.setMissionLabel("test",(result) => {
R
RayShih 已提交
1989
      console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
ahjxliubao2's avatar
ahjxliubao2 已提交
1990 1991 1992 1993
  });
  ```


Y
yuyaozhi 已提交
1994
## AbilityContext.setMissionLabel
ahjxliubao2's avatar
ahjxliubao2 已提交
1995

Y
yuyaozhi 已提交
1996
setMissionLabel(label: string): Promise&lt;void&gt;;
ahjxliubao2's avatar
ahjxliubao2 已提交
1997

1998
设置ability在任务中显示的名称(promise形式)。
ahjxliubao2's avatar
ahjxliubao2 已提交
1999

Y
yuyaozhi 已提交
2000
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
ahjxliubao2's avatar
ahjxliubao2 已提交
2001

Y
yuyaozhi 已提交
2002
**参数:**
ahjxliubao2's avatar
ahjxliubao2 已提交
2003

G
guyuanzhang 已提交
2004 2005 2006
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| label | string | 是 | 显示名称。 |
ahjxliubao2's avatar
ahjxliubao2 已提交
2007

Y
yuyaozhi 已提交
2008 2009
**返回值:**

G
guyuanzhang 已提交
2010 2011 2012
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 返回一个Promise,包含接口的结果。 |
ahjxliubao2's avatar
ahjxliubao2 已提交
2013

Y
yuyaozhi 已提交
2014
**示例:**
Z
zhangyafei.echo 已提交
2015

Y
yuyaozhi 已提交
2016
  ```js
F
fangJinliang1 已提交
2017 2018
  this.context.setMissionLabel("test").then(() => {
      console.log('success');
ahjxliubao2's avatar
ahjxliubao2 已提交
2019
  }).catch((error) => {
R
RayShih 已提交
2020
      console.log('failed:' + JSON.stringify(error));
ahjxliubao2's avatar
ahjxliubao2 已提交
2021 2022
  });
  ```
2023 2024 2025 2026
## AbilityContext.setMissionIcon

setMissionIcon(icon: image.PixelMap, callback:AsyncCallback\<void>): void;

2027
设置当前ability在任务中显示的图标(callback形式)。
2028 2029 2030 2031 2032 2033 2034 2035 2036

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
2037
| icon | image.PixelMap | 是 | 在最近的任务中显示的ability图标。 |
2038 2039 2040
| callback | AsyncCallback\<void> | 是 | 指定的回调函数的结果。 |

**示例:**
Z
zhangyafei.echo 已提交
2041

2042
  ```js
Y
yuyaozhi 已提交
2043
    import image from '@ohos.multimedia.image';
2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068
    var imagePixelMap;
    var color = new ArrayBuffer(0);
    var initializationOptions = {
       size: {
           height: 100,
           width: 100
       }
    };
    image.createPixelMap(color, initializationOptions)
       .then((data) => {
           imagePixelMap = data;
       })
       .catch((err) => {
           console.log('--------- createPixelMap fail, err: ---------', err)
       });
    this.context.setMissionIcon(imagePixelMap, (err) => {
       console.log('---------- setMissionIcon fail, err: -----------', err);
    })
  ```


## AbilityContext.setMissionIcon

setMissionIcon(icon: image.PixelMap): Promise\<void>;

2069
设置当前ability在任务中显示的图标(promise形式)。
2070 2071 2072 2073 2074 2075 2076 2077 2078

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**系统API**: 此接口为系统接口,三方应用不支持调用。

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
2079
| icon | image.PixelMap | 是 | 在最近的任务中显示的ability图标。 |
2080 2081 2082 2083 2084 2085 2086 2087

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 返回一个Promise,包含接口的结果。 |

**示例:**
Z
zhangyafei.echo 已提交
2088

2089
  ```js
Y
yuyaozhi 已提交
2090
    import image from '@ohos.multimedia.image';
2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106
    var imagePixelMap;
    var color = new ArrayBuffer(0);
    var initializationOptions = {
      size: {
          height: 100,
          width: 100
      }
    };
    image.createPixelMap(color, initializationOptions)
      .then((data) => {
          imagePixelMap = data;
      })
      .catch((err) => {
          console.log('--------- createPixelMap fail, err: ---------', err)
      });
    this.context.setMissionIcon(imagePixelMap)
F
fangJinliang1 已提交
2107 2108
      .then(() => {
          console.log('-------------- setMissionIcon success -------------');
2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133
      })
      .catch((err) => {
          console.log('-------------- setMissionIcon fail, err: -------------', err);
      });
  ```
## AbilityContext.restoreWindowStage

restoreWindowStage(localStorage: LocalStorage) : void;

恢复ability中的window stage数据。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| localStorage | image.LocalStorage | 是 | 用于恢复window stage的存储数据。 |

**示例:**

  ```js
    var storage = new LocalStorage();
    this.context.restoreWindowStage(storage);
  ```
ahjxliubao2's avatar
ahjxliubao2 已提交
2134

G
guyuanzhang 已提交
2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154
## AbilityContext.isTerminating

isTerminating(): boolean;

查询ability是否在terminating状态。

**系统能力**:SystemCapability.Ability.AbilityRuntime.Core

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| bool | true:ability当前处于terminating状态;false:不处于terminating状态。 |

**示例:**

  ```js
  var isTerminating = this.context.isTerminating();
  console.log('ability state :' + isTerminating);
  ```