js-apis-ability-context.md 15.5 KB
Newer Older
W
wusongqing 已提交
1 2
# AbilityContext

W
wusongqing 已提交
3 4 5 6
> **NOTE**
> 
> 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.  
> The APIs of this module can be used only in the stage model.
W
wusongqing 已提交
7

W
wusongqing 已提交
8
Implements the ability context. This module is inherited from **Context**.
W
wusongqing 已提交
9

W
wusongqing 已提交
10
## Modules to Import
W
wusongqing 已提交
11

W
wusongqing 已提交
12 13 14
```js
import Ability from '@ohos.application.Ability'
```
W
wusongqing 已提交
15 16 17 18
## Usage

Before using the **AbilityContext** module, you must define a child class that inherits from **Ability**.

W
wusongqing 已提交
19
```js
W
wusongqing 已提交
20 21 22 23 24 25 26 27 28
import Ability from '@ohos.application.Ability'
class MainAbility extends Ability {
    onWindowStageCreate(windowStage) {
        let context = this.context;
    }
}
```


W
wusongqing 已提交
29
## Attributes
W
wusongqing 已提交
30

W
wusongqing 已提交
31 32
**System capability**: SystemCapability.Ability.AbilityRuntime.Core

W
wusongqing 已提交
33
| Name| Type| Readable| Writable| Description|
W
wusongqing 已提交
34
| -------- | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
35 36
| abilityInfo | AbilityInfo | Yes| No| Ability information.|
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.|
W
wusongqing 已提交
37 38


W
wusongqing 已提交
39
## AbilityContext.startAbility
W
wusongqing 已提交
40 41 42

startAbility(want: Want, callback: AsyncCallback<void>): void

W
wusongqing 已提交
43
Starts an ability. This API uses a callback to return the result.
W
wusongqing 已提交
44

W
wusongqing 已提交
45
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
46

W
wusongqing 已提交
47
**Parameters**
W
wusongqing 已提交
48

W
wusongqing 已提交
49 50 51 52
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
53

W
wusongqing 已提交
54 55 56
**Example**

  ```js
W
wusongqing 已提交
57 58 59
  var want = {
  	"deviceId": "",
  	"bundleName": "com.extreme.test",
W
wusongqing 已提交
60
  	"abilityName": "MainAbility"
W
wusongqing 已提交
61 62 63 64 65 66 67
  };
  this.context.startAbility(want, (error) => {
      console.log("error.code = " + error.code)
  })
  ```


W
wusongqing 已提交
68
## AbilityContext.startAbility
W
wusongqing 已提交
69

W
wusongqing 已提交
70 71
startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void

W
wusongqing 已提交
72
Starts an ability. This API uses a callback to return the result.
W
wusongqing 已提交
73

W
wusongqing 已提交
74
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
75

W
wusongqing 已提交
76
**Parameters**
W
wusongqing 已提交
77

W
wusongqing 已提交
78 79 80
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md)  | Yes| Information about the **Want** used for starting an ability.|
W
wusongqing 已提交
81
| options | [StartOptions](js-apis-application-StartOptions.md) | Yes| Parameters used for starting the ability.|
W
wusongqing 已提交
82
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
83

W
wusongqing 已提交
84
**Example**
W
wusongqing 已提交
85
    
W
wusongqing 已提交
86
  ```js
W
wusongqing 已提交
87 88 89
  var want = {
  	"deviceId": "",
  	"bundleName": "com.extreme.test",
W
wusongqing 已提交
90
  	"abilityName": "MainAbility"
W
wusongqing 已提交
91 92 93 94 95 96 97 98 99 100
  };
  var options = {
  	windowMode: 0,
  };
  this.context.startAbility(want, options, (error) => {
      console.log("error.code = " + error.code)
  })
  ```


W
wusongqing 已提交
101
## AbilityContext.startAbility
W
wusongqing 已提交
102

W
wusongqing 已提交
103
startAbility(want: Want, options?: StartOptions): Promise<void>;
W
wusongqing 已提交
104

W
wusongqing 已提交
105
Starts an ability. This API uses a promise to return the result.
W
wusongqing 已提交
106

W
wusongqing 已提交
107
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
108

W
wusongqing 已提交
109
**Parameters**
W
wusongqing 已提交
110

W
wusongqing 已提交
111 112 113
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
W
wusongqing 已提交
114
| options | [StartOptions](js-apis-application-StartOptions.md) | No| Parameters used for starting the ability.|
W
wusongqing 已提交
115 116

**Return value**
W
wusongqing 已提交
117

W
wusongqing 已提交
118 119 120
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
W
wusongqing 已提交
121

W
wusongqing 已提交
122 123 124
**Example**

  ```js
W
wusongqing 已提交
125 126 127
  var want = {
  	"deviceId": "",
  	"bundleName": "com.extreme.test",
W
wusongqing 已提交
128
  	"abilityName": "MainAbility"
W
wusongqing 已提交
129
  };
W
wusongqing 已提交
130 131 132 133
  var options = {
  	windowMode: 0,
  };
  this.context.startAbility(want, options)
W
wusongqing 已提交
134 135 136 137 138 139 140 141
  .then((data) => {
      console.log('Operation successful.')
  }).catch((error) => {
      console.log('Operation failed.');
  })
  ```


W
wusongqing 已提交
142
## AbilityContext.startAbilityForResult
W
wusongqing 已提交
143 144 145

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

W
wusongqing 已提交
146
Starts an ability. This API uses a callback to return the result when the ability is terminated.
W
wusongqing 已提交
147

W
wusongqing 已提交
148
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
149

W
wusongqing 已提交
150
**Parameters**
W
wusongqing 已提交
151

W
wusongqing 已提交
152 153 154 155
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
| callback | AsyncCallback<[AbilityResult](js-apis-featureAbility.md#abilityresult)> | Yes| Callback used to return the result.|
W
wusongqing 已提交
156 157


W
wusongqing 已提交
158 159 160
**Example**

  ```js
W
wusongqing 已提交
161
  this.context.startAbilityForResult(
W
wusongqing 已提交
162
      {deviceId: "", bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"},
W
wusongqing 已提交
163 164 165 166 167 168 169
      (error, result) => {
          console.log("startAbilityForResult AsyncCallback is called, error.code = " + error.code)
          console.log("startAbilityForResult AsyncCallback is called, result.resultCode = " + result.resultCode)
       }
  );
  ```

W
wusongqing 已提交
170
## AbilityContext.startAbilityForResult
W
wusongqing 已提交
171 172 173

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

W
wusongqing 已提交
174
Starts an ability. This API uses a callback to return the result when the ability is terminated.
W
wusongqing 已提交
175

W
wusongqing 已提交
176
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
177

W
wusongqing 已提交
178
**Parameters**
W
wusongqing 已提交
179

W
wusongqing 已提交
180 181 182
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
W
wusongqing 已提交
183
| options | [StartOptions](js-apis-application-StartOptions.md) | Yes| Parameters used for starting the ability.|
W
wusongqing 已提交
184
| callback | AsyncCallback<[AbilityResult](js-apis-featureAbility.md#abilityresult)> | Yes| Callback used to return the result.|
W
wusongqing 已提交
185 186


W
wusongqing 已提交
187 188 189
**Example**

  ```js
W
wusongqing 已提交
190 191 192 193
  var options = {
    windowMode: 0,
  };
  this.context.startAbilityForResult(
W
wusongqing 已提交
194
      {deviceId: "", bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, options,
W
wusongqing 已提交
195 196 197 198 199 200 201
      (error, result) => {
          console.log("startAbilityForResult AsyncCallback is called, error.code = " + error.code)
          console.log("startAbilityForResult AsyncCallback is called, result.resultCode = " + result.resultCode)
       }
  );
  ```

W
wusongqing 已提交
202

W
wusongqing 已提交
203
## AbilityContext.startAbilityForResult
W
wusongqing 已提交
204

W
wusongqing 已提交
205
startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityResult>;
W
wusongqing 已提交
206

W
wusongqing 已提交
207
Starts an ability. This API uses a promise to return the result when the ability is terminated.
W
wusongqing 已提交
208

W
wusongqing 已提交
209
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
210

W
wusongqing 已提交
211
**Parameters**
W
wusongqing 已提交
212

W
wusongqing 已提交
213 214 215
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
W
wusongqing 已提交
216
| options | [StartOptions](js-apis-application-StartOptions.md) | No| Parameters used for starting the ability.|
W
wusongqing 已提交
217

W
wusongqing 已提交
218

W
wusongqing 已提交
219 220
**Return value**

W
wusongqing 已提交
221 222 223
| Type| Description|
| -------- | -------- |
| Promise<[AbilityResult](js-apis-featureAbility.md#abilityresult)> | Promise used to return the result.|
W
wusongqing 已提交
224

W
wusongqing 已提交
225 226 227
**Example**

  ```js
W
wusongqing 已提交
228 229 230
  var options = {
    windowMode: 0,
  };
W
wusongqing 已提交
231
  this.context.startAbilityForResult({deviceId: "", bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, options).then((result) => {
W
wusongqing 已提交
232 233 234 235 236 237 238
      console.log("startAbilityForResult Promise.resolve is called, result.resultCode = " + result.resultCode)
  }, (error) => {
      console.log("startAbilityForResult Promise.Reject is called, error.code = " + error.code)
  })
  ```


W
wusongqing 已提交
239
## AbilityContext.terminateSelf
W
wusongqing 已提交
240 241 242

terminateSelf(callback: AsyncCallback<void>): void;

W
wusongqing 已提交
243
Terminates this ability. This API uses a callback to return the result.
W
wusongqing 已提交
244

W
wusongqing 已提交
245
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
246

W
wusongqing 已提交
247
**Parameters**
W
wusongqing 已提交
248

W
wusongqing 已提交
249 250 251
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<void> | Yes| Callback used to return the result indicating whether the API is successfully called.|
W
wusongqing 已提交
252

W
wusongqing 已提交
253 254 255
**Example**

  ```js
W
wusongqing 已提交
256
  this.context.terminateSelf((err) => {
W
wusongqing 已提交
257
      console.log('terminateSelf result:' + JSON.stringify(err));
W
wusongqing 已提交
258
  });
W
wusongqing 已提交
259 260 261
  ```


W
wusongqing 已提交
262
## AbilityContext.terminateSelf
W
wusongqing 已提交
263 264 265

terminateSelf(): Promise<void>;

W
wusongqing 已提交
266
Terminates this ability. This API uses a promise to return the result.
W
wusongqing 已提交
267

W
wusongqing 已提交
268
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
269

W
wusongqing 已提交
270
**Return value**
W
wusongqing 已提交
271

W
wusongqing 已提交
272 273 274
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result indicating whether the API is successfully called.|
W
wusongqing 已提交
275

W
wusongqing 已提交
276 277 278
**Example**

  ```js
W
wusongqing 已提交
279
  this.context.terminateSelf(want).then((data) => {
W
wusongqing 已提交
280
      console.log('success:' + JSON.stringify(data));
W
wusongqing 已提交
281
  }).catch((error) => {
W
wusongqing 已提交
282
      console.log('failed:' + JSON.stringify(error));
W
wusongqing 已提交
283 284 285 286
  });
  ```


W
wusongqing 已提交
287
## AbilityContext.terminateSelfWithResult
W
wusongqing 已提交
288 289 290

terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void;

W
wusongqing 已提交
291
Terminates this ability. This API uses a callback to return the information to the caller of **startAbilityForResult**.
W
wusongqing 已提交
292

W
wusongqing 已提交
293
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
294

W
wusongqing 已提交
295
**Parameters**
W
wusongqing 已提交
296

W
wusongqing 已提交
297 298 299 300
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
301

W
wusongqing 已提交
302 303 304
**Example**

  ```js
W
wusongqing 已提交
305 306 307 308 309 310 311 312 313 314 315
  this.context.terminateSelfWithResult(
     {
          want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
          resultCode: 100
      }, (error) => {
          console.log("terminateSelfWithResult is called = " + error.code)
      }
  );
  ```


W
wusongqing 已提交
316
## AbilityContext.terminateSelfWithResult
W
wusongqing 已提交
317 318 319

terminateSelfWithResult(parameter: AbilityResult): Promise<void>;

W
wusongqing 已提交
320
Terminates this ability. This API uses a promise to return information to the caller of **startAbilityForResult**.
W
wusongqing 已提交
321

W
wusongqing 已提交
322
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
323

W
wusongqing 已提交
324
**Parameters**
W
wusongqing 已提交
325

W
wusongqing 已提交
326 327 328
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
W
wusongqing 已提交
329

W
wusongqing 已提交
330 331
**Return value**

W
wusongqing 已提交
332 333 334
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
W
wusongqing 已提交
335

W
wusongqing 已提交
336 337 338
**Example**

  ```js
W
wusongqing 已提交
339 340 341 342 343 344 345 346 347
  this.context.terminateSelfWithResult(
  {
      want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
      resultCode: 100
  }).then((result) => {
      console.log("terminateSelfWithResult")
  }
  )
  ```
W
wusongqing 已提交
348 349


W
wusongqing 已提交
350
## AbilityContext.startAbilityByCall
W
wusongqing 已提交
351 352 353 354 355

startAbilityByCall(want: Want): Promise<Caller>;

Obtains the caller interface of the specified ability, and if the specified ability is not started, starts the ability in the background.

W
wusongqing 已提交
356
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
357

W
wusongqing 已提交
358
**Parameters**
W
wusongqing 已提交
359

W
wusongqing 已提交
360 361 362
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to start, including the ability name, bundle name, and device ID. If the device ID is left blank or the default value is used, the local ability will be started.|
W
wusongqing 已提交
363

W
wusongqing 已提交
364 365
**Return value**

W
wusongqing 已提交
366 367 368
| Type| Description|
| -------- | -------- |
| Promise<Caller> | Promise used to return the caller object to communicate with.|
W
wusongqing 已提交
369

W
wusongqing 已提交
370
**Example**
W
wusongqing 已提交
371
    
W
wusongqing 已提交
372
  ```js
W
wusongqing 已提交
373 374 375 376 377 378
  import Ability from '@ohos.application.Ability';
  var caller;
  export default class MainAbility extends Ability {
      onWindowStageCreate(windowStage) {
          this.context.startAbilityByCall({
              bundleName: "com.example.myservice",
W
wusongqing 已提交
379
              abilityName: "MainAbility",
W
wusongqing 已提交
380 381 382
              deviceId: ""
          }).then((obj) => {
              caller = obj;
W
wusongqing 已提交
383
              console.log('Caller GetCaller Get ' + caller);
W
wusongqing 已提交
384 385 386 387 388 389 390 391
          }).catch((e) => {
              console.log('Caller GetCaller error ' + e);
          });
      }
  }
  ```


W
wusongqing 已提交
392
## AbilityContext.requestPermissionsFromUser
W
wusongqing 已提交
393 394 395

requestPermissionsFromUser(permissions: Array<string>, requestCallback: AsyncCallback<PermissionRequestResult>) : void;

W
wusongqing 已提交
396
Requests permissions from the user by displaying a pop-up window. This API uses a callback to return the result.
W
wusongqing 已提交
397

W
wusongqing 已提交
398
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
399

W
wusongqing 已提交
400
**Parameters**
W
wusongqing 已提交
401

W
wusongqing 已提交
402 403 404 405
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| permissions | Array<string> | Yes| Permissions to request.|
| callback | AsyncCallback<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Yes| Callback used to return the result indicating whether the API is successfully called.|
W
wusongqing 已提交
406

W
wusongqing 已提交
407
**Example**
W
wusongqing 已提交
408
    
W
wusongqing 已提交
409 410 411 412
  ```js
       var permissions=['com.example.permission']
       this.context.requestPermissionsFromUser(permissions,(result) => {
       console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
W
wusongqing 已提交
413
  });
W
wusongqing 已提交
414
  
W
wusongqing 已提交
415 416 417
  ```


W
wusongqing 已提交
418
## AbilityContext.requestPermissionsFromUser
W
wusongqing 已提交
419 420 421

requestPermissionsFromUser(permissions: Array<string>) : Promise<PermissionRequestResult>;

W
wusongqing 已提交
422
Requests permissions from the user by displaying a pop-up window. This API uses a promise to return the result.
W
wusongqing 已提交
423

W
wusongqing 已提交
424
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
425

W
wusongqing 已提交
426
**Parameters**
W
wusongqing 已提交
427

W
wusongqing 已提交
428 429 430
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| permissions | Array<string> | Yes| Permissions to request.|
W
wusongqing 已提交
431 432

**Return value**
W
wusongqing 已提交
433

W
wusongqing 已提交
434 435 436
| Type| Description|
| -------- | -------- |
| Promise<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Promise used to return the result indicating whether the API is successfully called.|
W
wusongqing 已提交
437

W
wusongqing 已提交
438
**Example**
W
wusongqing 已提交
439
    
W
wusongqing 已提交
440 441 442
  ```js
   var permissions=['com.example.permission']
       this.context.requestPermissionsFromUser(permissions).then((data) => {
W
wusongqing 已提交
443
      console.log('success:' + JSON.stringify(data));
W
wusongqing 已提交
444
  }).catch((error) => {
W
wusongqing 已提交
445
      console.log('failed:' + JSON.stringify(error));
W
wusongqing 已提交
446
  });
W
wusongqing 已提交
447

W
wusongqing 已提交
448 449 450
  ```


W
wusongqing 已提交
451
## AbilityContext.setMissionLabel
W
wusongqing 已提交
452 453 454

setMissionLabel(label: string, callback:AsyncCallback<void>): void;

W
wusongqing 已提交
455
Sets the label of the ability in the mission. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
456

W
wusongqing 已提交
457
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
458

W
wusongqing 已提交
459
**Parameters**
W
wusongqing 已提交
460

W
wusongqing 已提交
461 462 463 464
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result indicating whether the API is successfully called.|
W
wusongqing 已提交
465

W
wusongqing 已提交
466
**Example**
W
wusongqing 已提交
467
    
W
wusongqing 已提交
468
  ```js
W
wusongqing 已提交
469
  this.context.setMissionLabel("test",(result) => {
W
wusongqing 已提交
470
      console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
W
wusongqing 已提交
471 472 473 474
  });
  ```


W
wusongqing 已提交
475
## AbilityContext.setMissionLabel
W
wusongqing 已提交
476 477 478

setMissionLabel(label: string): Promise<void>

W
wusongqing 已提交
479
Sets the label of the ability in the mission. This API uses a promise to return the result.
W
wusongqing 已提交
480

W
wusongqing 已提交
481
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
482

W
wusongqing 已提交
483
**Parameters**
W
wusongqing 已提交
484

W
wusongqing 已提交
485 486 487
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.|
W
wusongqing 已提交
488

W
wusongqing 已提交
489 490
**Return value**

W
wusongqing 已提交
491 492 493
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result indicating whether the API is successfully called.|
W
wusongqing 已提交
494

W
wusongqing 已提交
495
**Example**
W
wusongqing 已提交
496
    
W
wusongqing 已提交
497
  ```js
W
wusongqing 已提交
498
  this.context.setMissionLabel("test").then((data) => {
W
wusongqing 已提交
499
      console.log('success:' + JSON.stringify(data));
W
wusongqing 已提交
500
  }).catch((error) => {
W
wusongqing 已提交
501
      console.log('failed:' + JSON.stringify(error));
W
wusongqing 已提交
502 503
  });
  ```
W
wusongqing 已提交
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524

## AbilityContext.isTerminating

isTerminating(): boolean;

Checks whether this ability is in the terminating state.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Return value**

| Type| Description|
| -------- | -------- |
| bool | The value **true** means that the ability is in terminating state, and **false** means the opposite.|

**Example**

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