• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.InputMethodExtensionContext (InputMethodExtensionContext)
2
3The **InputMethodExtensionContext** module, inherited from **ExtensionContext**, provides context for **InputMethodExtension** abilities.
4
5You can use the APIs of this module to start, terminate, connect, and disconnect abilities.
6
7> **NOTE**
8>
9>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.
10
11## Modules to Import
12
13```
14import InputMethodExtensionContext from '@ohos.InputMethodExtensionContext';
15```
16
17## Usage
18
19Before using the **InputMethodExtensionContext** module, you must define a child class that inherits from **InputMethodExtensionAbility**.
20
21```js
22import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility';
23class EntryAbility extends InputMethodExtensionAbility {
24    onCreate() {
25        let context = this.context;
26    }
27}
28```
29
30## InputMethodExtensionContext.destroy
31
32destroy(callback: AsyncCallback\<void>): void
33
34Terminates this ability. This API uses an asynchronous callback to return the result.
35
36**System capability**: SystemCapability.MiscServices.InputMethodFramework
37
38**Parameters**
39
40| Name  | Type                | Mandatory| Description                                                        |
41| -------- | -------------------- | ---- | ------------------------------------------------------------ |
42| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
43
44**Example**
45
46```js
47this.context.destroy((err) => {
48    console.log('destroy result:' + JSON.stringify(err));
49});
50```
51
52## InputMethodExtensionContext.destroy
53
54destroy(): Promise\<void>;
55
56Terminates this ability. This API uses a promise to return the result.
57
58**System capability**: SystemCapability.MiscServices.InputMethodFramework
59
60**Return value**
61
62| Type| Description|
63| -------- | -------- |
64| Promise\<void>; | Promise that returns no value.|
65
66**Example**
67
68```js
69this.context.destroy().then(() => {
70    console.log('Succeeded in destroying context.');
71}).catch((error) => {
72    console.log('Failed to destroy context: ' + JSON.stringify(error));
73});
74```
75