1#  @ohos.app.ability.application (Application) (System API)
2You can use this module to create a [Context](../../application-models/application-context-stage.md).
3
4> **NOTE**
5>
6> 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.
7> The APIs of this module can be used only in the stage model.
8
9## Modules to Import
10
11```ts
12import { application } from '@kit.AbilityKit';
13```
14## application.createModuleContext<sup>12+</sup>
15
16createModuleContext(context: Context, bundleName: string, moduleName: string): Promise\<Context>
17
18Creates the context for a module.
19
20
21**Atomic service API**: This API can be used in atomic services since API version 12.
22
23**System capability**: SystemCapability.Ability.AbilityRuntime.Core
24
25**System API**: This is a system API.
26
27**Parameters**
28
29| Name       | Type                                      | Mandatory  | Description            |
30| --------- | ---------------------------------------- | ---- | -------------- |
31| context | [Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md) | Yes| Application context.|
32| bundleName | string   | Yes   | Bundle name of the application. If an empty string is passed in, the current application is used by default.|
33| moduleName | string | Yes| Module name.|
34
35**Return value**
36
37| Type              | Description               |
38| ------------------ | ------------------- |
39| Promise\<[Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md)> | Promise used to return the context created.|
40
41**Error codes**
42
43For details about the error codes, see [Ability Error Codes](errorcode-ability.md).
44
45| ID| Error Message       |
46| -------- | --------------- |
47| 201 | Permission denied. |
48| 202 | Permission denied, non-system app called system api.|
49| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
50
51**Example**
52
53```ts
54import { UIAbility, application} from '@kit.AbilityKit';
55import { BusinessError } from '@kit.BasicServicesKit';
56
57export default class EntryAbility extends UIAbility {
58  onCreate() {
59    let moduleContext: common.Context;
60    try {
61      application.createModuleContext(this.context, 'bundlename', 'entry').then((data: Context)=>{
62        moduleContext = data;
63        console.info('createModuleContext success!');
64      }).catch((error : BusinessError)=>{
65        console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
66      })
67    } catch (error) {
68      console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
69    }
70  }
71}
72```
73
74## application.createBundleContext<sup>12+</sup>
75
76createBundleContext(context: Context, bundleName: string): Promise\<Context>
77
78Creates the context for an application.
79
80
81**Atomic service API**: This API can be used in atomic services since API version 12.
82
83**System capability**: SystemCapability.Ability.AbilityRuntime.Core
84
85**System API**: This is a system API.
86
87**Parameters**
88
89| Name       | Type                                      | Mandatory  | Description            |
90| --------- | ---------------------------------------- | ---- | -------------- |
91| context | [Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md) | Yes| Application context.|
92| bundleName | string   | Yes   | Bundle name of the application.|
93
94**Return value**
95
96| Type              | Description               |
97| ------------------ | ------------------- |
98| Promise\<[Context](../../reference/apis-ability-kit/js-apis-inner-application-context.md)> | Promise used to return the context created.|
99
100**Error codes**
101
102For details about the error codes, see [Ability Error Codes](errorcode-ability.md).
103
104| ID| Error Message       |
105| -------- | --------------- |
106| 201 | Permission denied. |
107| 202 | Permission denied, non-system app called system api.|
108| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
109
110
111**Example**
112
113```ts
114import { UIAbility, application} from '@kit.AbilityKit';
115import { BusinessError } from '@kit.BasicServicesKit';
116
117export default class EntryAbility extends UIAbility {
118  onCreate() {
119    let moduleContext: common.Context;
120    try {
121      application.createBundleContext(this.context, 'bundlename').then((data: Context)=>{
122        moduleContext = data;
123        console.info('createBundleContext success!');
124      }).catch((error : BusinessError)=>{
125        console.error(`createBundleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
126      })
127    } catch (error) {
128      console.error(`createBundleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
129    }
130  }
131}
132```
133