1# FormExtensionContext 2 3The **FormExtensionContext** module, inherited from **ExtensionContext**, provides context for FormExtensionAbilities. 4 5You can use the APIs of this module to start FormExtensionAbilities. 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> The APIs of this module can be used only in the stage model. 11 12## Usage 13 14Before using the **ServiceExtensionContext** module, you must first obtain a **FormExtensionAbility** instance. 15 16```ts 17import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; 18import formBindingData from '@ohos.app.form.formBindingData'; 19export default class MyFormExtensionAbility extends FormExtensionAbility { 20 onAddForm() { 21 let formContext = this.context; // 获取FormExtensionContext 22 // ... 23 let dataObj1 = { 24 temperature:'11c', 25 'time':'11:00' 26 }; 27 let obj1 = formBindingData.createFormBindingData(dataObj1); 28 return obj1; 29 } 30} 31``` 32 33## startAbility 34 35startAbility(want: Want, callback: AsyncCallback<void>): void 36 37Starts an ability. This API uses an asynchronous callback to return the result. 38 39**System API**: This is a system API. 40 41**System capability**: SystemCapability.Ability.Form 42 43**Parameters** 44 45| Name| Type | Mandatory| Description | 46| ------| --------------------------------- | ---- | -------------------------------------- | 47| want| [Want](js-apis-application-want.md) | Yes | Information about the ability to start, such as the bundle name, ability name, and custom parameters.| 48| callback| AsyncCallback<void> | Yes | Callback used to return the result. If the ability is started, **err** is undefined; otherwise, **err** is an error object.| 49 50**Example** 51 52```ts 53let want = { 54 deviceId: '', 55 bundleName: 'com.example.formstartability', 56 abilityName: 'MainAbility', 57 action: 'action1', 58 entities: ['entity1'], 59 type: 'MIMETYPE', 60 uri: 'key={true,true,false}', 61 parameters: {} 62}; 63this.context.startAbility(want, (error, data) => { 64 if (error) { 65 console.log('FormExtensionContext startAbility, error:' + JSON.stringify(error)); 66 } else { 67 console.log(`FormExtensionContext startAbility success`); 68 } 69}); 70``` 71 72## startAbility 73 74startAbility(want: Want): Promise<void> 75 76Starts an ability. This API uses a promise to return the result. 77 78**System API**: This is a system API. 79 80**System capability**: SystemCapability.Ability.Form 81 82**Parameters** 83 84| Name| Type | Mandatory| Description | 85| ------| --------------------------------- | ---- | -------------------------------------- | 86| want| [Want](js-apis-application-want.md) | Yes | Information about the ability to start, such as the bundle name, ability name, and custom parameters.| 87 88**Return value** 89 90| Type | Description | 91| ------------ | ---------------------------------- | 92| Promise<void< | Promise that returns no value.| 93 94**Example** 95 96```ts 97let want = { 98 deviceId: '', 99 bundleName: 'com.example.formstartability', 100 abilityName: 'MainAbility', 101 action: 'action1', 102 entities: ['entity1'], 103 type: 'MIMETYPE', 104 uri: 'key={true,true,false}', 105 parameters: {} 106}; 107this.context.startAbility(want).then(() => { 108 console.info('StartAbility Success'); 109}).catch((error) => { 110 console.info('StartAbility failed'); 111}); 112``` 113