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](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        let code: number = (error as BusinessError).code;
62        let message: string = (error as BusinessError).message;
63        console.error(`createModuleContext failed, error.code: ${code}, error.message: ${message}`);
64      })
65    } catch (error) {
66      let code: number = (error as BusinessError).code;
67      let message: string = (error as BusinessError).message;
68      console.error(`createModuleContext failed, error.code: ${code}, error.message: ${message}`);
69    }
70  }
71}
72```
73
74## application.getApplicationContext<sup>14+</sup>
75
76getApplicationContext(): ApplicationContext
77
78Obtains the application context.
79> **NOTE**
80>
81>The application context obtained through this API can only be used to obtain the corresponding [application information](js-apis-bundleManager-applicationInfo.md) and all [sandbox paths](js-apis-inner-application-context.md#properties).
82
83**Atomic service API**: This API can be used in atomic services since API version 14.
84
85**System capability**: SystemCapability.Ability.AbilityRuntime.Core
86
87**Return value**
88
89| Type                                                        | Description               |
90| ------------------------------------------------------------ | ------------------- |
91| [ApplicationContext](js-apis-inner-application-applicationContext.md) | Application context obtained.|
92
93**Error codes**
94
95For details about the error codes, see [Ability Error Codes](errorcode-ability.md).
96
97| ID| Error Message       |
98| -------- | --------------- |
99| 16000050 | Internal error. |
100
101**Example**
102
103```ts
104import { UIAbility, application } from '@kit.AbilityKit';
105import { BusinessError } from '@kit.BasicServicesKit';
106
107export default class EntryAbility extends UIAbility {
108  onCreate(): void {
109    try {
110      let applicationContext = application.getApplicationContext();
111    } catch (error) {
112      let code: number = (error as BusinessError).code;
113      let message: string = (error as BusinessError).message;
114      console.error(`getApplicationContext failed, error.code: ${code}, error.message: ${message}`);
115    }
116  }
117}
118```
119