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