1# ApplicationContext (System API) 2 3The ApplicationContext module, inherited from [Context](js-apis-inner-application-context.md), provides application-level context capabilities, including APIs for registering and deregistering the lifecycle of application components. 4 5> **NOTE** 6> 7> 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. 8> 9> This topic describes only system APIs provided by the module. For details about its public APIs, see [ApplicationContext](js-apis-inner-application-applicationContext.md). 10 11## Modules to Import 12 13```ts 14import { common } from '@kit.AbilityKit'; 15``` 16 17## Instructions 18 19Before calling any APIs in **ApplicationContext**, obtain an **ApplicationContext** instance through the **context** instance. 20 21## ApplicationContext.preloadUIExtensionAbility<sup>12+</sup> 22 23preloadUIExtensionAbility(want: Want): Promise\<void\> 24 25Preloads a **UIExtensionAbility** instance. 26 27The preloaded **UIExtensionAbility** instance is sent to the **onCreate** lifecycle of the UIExtensionAbility and waits to be loaded by the current application. 28 29A **UIExtensionAbility** instance can be preloaded for multiple times. Each time a preloaded **UIExtensionAbility** instance is loaded, the next preloaded **UIExtensionAbility** instance is sent to the **onCreate** lifecycle of the UIExtensionAbility. 30 31**System capability**: SystemCapability.Ability.AbilityRuntime.Core 32 33**System API**: This is a system API. 34 35| Name| Type| Mandatory| Description| 36| -------- | -------- | -------- | -------- | 37| want | [Want](js-apis-app-ability-want.md) | Yes| Want information of the UIExtensionAbility.| 38 39**Return value** 40 41| Type| Description| 42| -------- | -------- | 43| Promise<void> | Promise that returns no value.| 44 45**Error codes** 46 47For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 48 49| ID| Error Message| 50| ------- | -------------------------------- | 51| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 52| 16000001 | The specified ability does not exist. | 53| 16000002 | Incorrect ability type. | 54| 16000004 | Failed to start the invisible ability. | 55| 16200011 | The context does not exist. | 56| 16000050 | Internal error. | 57 58**Example** 59 60```ts 61import { UIAbility, Want } from '@kit.AbilityKit'; 62import { BusinessError } from '@kit.BasicServicesKit'; 63 64export default class EntryAbility extends UIAbility { 65 onCreate() { 66 let want: Want = { 67 bundleName: 'com.ohos.uiextensionprovider', 68 abilityName: 'UIExtensionProvider', 69 moduleName: 'entry', 70 parameters: { 71 // The value must be the same as the value of type in the module.json5 file of the UIExtensionAbility. 72 'ability.want.params.uiExtensionType': 'sys/commonUI' 73 } 74 }; 75 try { 76 let applicationContext = this.context.getApplicationContext(); 77 applicationContext.preloadUIExtensionAbility(want) 78 .then(() => { 79 // Carry out normal service processing. 80 console.info('preloadUIExtensionAbility succeed'); 81 }) 82 .catch((err: BusinessError) => { 83 // Process service logic errors. 84 console.error('preloadUIExtensionAbility failed'); 85 }); 86 } catch (err) { 87 // Process input parameter errors. 88 let code = (err as BusinessError).code; 89 let message = (err as BusinessError).message; 90 console.error(`preloadUIExtensionAbility failed. code: ${code}, msg: ${message}`); 91 } 92 } 93} 94``` 95