1#  @ohos.app.ability.application (Application)
2
3You can use this module to create a [Context](../../application-models/application-context-stage.md).
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> The APIs of this module can be used only in the stage model.
9
10## Modules to Import
11
12```ts
13import { application } from '@kit.AbilityKit';
14```
15
16## application.createModuleContext<sup>12+</sup>
17
18createModuleContext(context: Context, moduleName: string): Promise\<Context>
19
20Creates the context for a module.
21
22**Atomic service API**: This API can be used in atomic services since API version 12.
23
24**System capability**: SystemCapability.Ability.AbilityRuntime.Core
25
26**Parameters**
27
28| Name       | Type                                      | Mandatory  | Description            |
29| --------- | ---------------------------------------- | ---- | -------------- |
30| context | [Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md) | Yes| Application context.| 
31| moduleName | string | Yes| Module name.|
32
33**Return value**
34
35| Type              | Description               |
36| ------------------ | ------------------- |
37| Promise\<[Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md)> | Promise used to return the context created.|
38
39**Error codes**
40
41For details about the error codes, see [Ability Error Codes](errorcode-ability.md).
42
43| ID| Error Message       |
44| -------- | --------------- |
45| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
46
47**Example**
48
49```ts
50import { UIAbility, application, common } from '@kit.AbilityKit';
51import { BusinessError } from '@kit.BasicServicesKit';
52
53export default class EntryAbility extends UIAbility {
54  onCreate() {
55    let moduleContext: common.Context;
56    try {
57      application.createModuleContext(this.context,'entry').then((data: Context)=>{
58        moduleContext = data;
59        console.info('createBundleContext success!');
60      }).catch((error : BusinessError)=>{
61        console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
62      })
63    } catch (error) {
64      console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
65    }
66  }
67}
68```
69