1# Ability Subsystem Changelog
2
3## cl.ability.1 Deprecated the createModuleContext API
4
5**Access Level**
6
7Public API
8
9**Reason for Change**
10
11The context created using this API cannot obtain resources correctly.
12
13**Change Impact**
14
15This change is a compatibility change. A new API is provided.
16
17**Start API Level**
18
199
20
21**Change Since**
22
23OpenHarmony SDK 5.0.0.37
24
25**Deprecated APIs/Components**
26
27|Deprecated API|Description|Substitute API|
28|-------|-------|-------|
29|createModuleContext(moduleName: string): Context|The context created using this API cannot obtain resources correctly. You are advised to use the substitute API.|createModuleContext(context: Context, moduleName: string): Promise\<Context>|
30
31**Adaptation Guide**
32
33Use **createModuleContext** with the input parameter **context** in the code.
34
35Code example before deprecation:
36
37```ts
38import { common, UIAbility } from '@kit.AbilityKit';
39import { BusinessError } from '@kit.BasicServicesKit';
40
41export default class EntryAbility extends UIAbility {
42  onCreate() {
43    console.log('MyAbility onCreate');
44    let moduleContext: common.Context;
45    try {
46      moduleContext = this.context.createModuleContext('entry');
47    } catch (error) {
48      console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
49    }
50  }
51}
52```
53Code example after deprecation:
54
55```ts
56import { common, UIAbility } from '@kit.AbilityKit';
57import { BusinessError } from '@kit.BasicServicesKit';
58
59export default class EntryAbility extends UIAbility {
60  onCreate() {
61    console.log('MyAbility onCreate');
62    let moduleContext: common.Context;
63    try {
64      common.createModuleContext(this.context,'entry').then((data: Context)=>{
65        moduleContext = data;
66      }).catch((err : BusinessError)=>{
67        console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
68      })
69    } catch (error) {
70      console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
71    }
72  }
73}
74```
75## cl.ability.2 Deprecated the createModuleContext API
76
77**Access Level**
78
79System API
80
81**Reason for Change**
82
83The context created using this API cannot obtain resources correctly.
84
85**Change Impact**
86
87This change is a compatibility change. A new API is provided.
88
89**Start API Level**
90
919
92
93**Change Since**
94
95OpenHarmony SDK 5.0.0.37
96
97**Deprecated APIs/Components**
98
99|Deprecated API|Description|Substitute API|
100|-------|-------|-------|
101|createModuleContext(bundleName: string, moduleName: string): Context|The context created using this API cannot obtain resources correctly. You are advised to use the substitute API.|createModuleContext(context: Context, bundleName: string, moduleName: string): Promise\<Context>|
102
103**Adaptation Guide**
104
105Use **createModuleContext** with the input parameter **context** in the code.
106
107Code example before deprecation:
108
109```ts
110import { common, UIAbility } from '@kit.AbilityKit';
111import { BusinessError } from '@kit.BasicServicesKit';
112
113export default class EntryAbility extends UIAbility {
114  onCreate() {
115    console.log('MyAbility onCreate');
116    let moduleContext: common.Context;
117    try {
118      moduleContext = this.context.createModuleContext('bunlename', 'entry');
119    } catch (error) {
120      console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
121    }
122  }
123}
124```
125Code example after deprecation:
126
127```ts
128import { common, UIAbility } from '@kit.AbilityKit';
129import { BusinessError } from '@kit.BasicServicesKit';
130
131export default class EntryAbility extends UIAbility {
132  onCreate() {
133    console.log('MyAbility onCreate');
134    let moduleContext: common.Context;
135    try {
136      common.createModuleContext(this.context, 'bunlename', 'entry').then((data: Context)=>{
137        moduleContext = data;
138      }).catch((err : BusinessError)=>{
139        console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
140      })
141    } catch (error) {
142      console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
143    }
144  }
145}
146```
147
148## cl.ability.3 Deprecated the createBundleContext API
149
150**Access Level**
151
152System API
153
154**Reason for Change**
155
156The context created using this API cannot obtain resources correctly.
157
158**Change Impact**
159
160This change is a compatibility change. A new API is provided.
161
162**Start API Level**
163
1649
165
166**Change Since**
167
168OpenHarmony SDK 5.0.0.37
169
170**Deprecated APIs/Components**
171
172|Deprecated API|Description|Substitute API|
173|-------|-------|-------|
174|createBundleContext(bundleName: string): Context|The context created using this API cannot obtain resources correctly. You are advised to use the substitute API.|createBundleContext(context: Context, bundleName: string): Promise\<Context>|
175
176**Adaptation Guide**
177
178Use **createBundleContext** with the input parameter **context** in the code.
179
180Code example before deprecation:
181
182```ts
183import { common, UIAbility } from '@kit.AbilityKit';
184import { BusinessError } from '@kit.BasicServicesKit';
185
186export default class EntryAbility extends UIAbility {
187  onCreate() {
188    console.log('MyAbility onCreate');
189    let bundleContext: common.Context;
190    try {
191      bundleContext = this.context.createBundleContext('bundlename');
192    } catch (error) {
193      console.error(`createBundleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
194    }
195  }
196}
197```
198Code example after deprecation:
199
200```ts
201import { common, UIAbility } from '@kit.AbilityKit';
202import { BusinessError } from '@kit.BasicServicesKit';
203
204export default class EntryAbility extends UIAbility {
205  onCreate() {
206    console.log('MyAbility onCreate');
207    let bundleContext: common.Context;
208    try {
209      common.createBundleContext(this.context,'bundlename').then((data: Context)=>{
210        bundleContext = data;
211      }).catch((err : BusinessError)=>{
212        console.error(`createBundleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
213      })
214    } catch (error) {
215      console.error(`createBundleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`);
216    }
217  }
218}
219```
220