提交 8a1f1465 编写于 作者: W wangkai

9-13

Signed-off-by: Nwangkai <wangkai424@huawei.com>
上级 3bf238ca
...@@ -49,20 +49,20 @@ export default class MyAbilityStage extends AbilityStage { ...@@ -49,20 +49,20 @@ export default class MyAbilityStage extends AbilityStage {
console.log("MyAbilityStage onCreate") console.log("MyAbilityStage onCreate")
let context = this.context let context = this.context
const kvManagerConfig = { const kvManagerConfig = {
context: context, context: context,
bundleName: 'com.example.datamanagertest', bundleName: 'com.example.datamanagertest',
userInfo: { userInfo: {
userId: '0', userId: '0',
userType: distributedData.UserType.SAME_USER_ID userType: distributedData.UserType.SAME_USER_ID
} }
} }
distributedData.createKVManager(kvManagerConfig, function (err, manager) { distributedData.createKVManager(kvManagerConfig, function (err, manager) {
if (err) { if (err) {
console.log("Failed to create KVManager: " + JSON.stringify(err)); console.log("Failed to create KVManager: " + JSON.stringify(err));
return; return;
} }
console.log("Succeeded in creating KVManager"); console.log("Succeeded in creating KVManager");
kvManager = manager; kvManager = manager;
}); });
} }
} }
...@@ -72,7 +72,6 @@ FA模型下的示例: ...@@ -72,7 +72,6 @@ FA模型下的示例:
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
let kvManager; let kvManager;
console.log("MyAbilityStage onCreate")
let context = featureAbility.getContext() let context = featureAbility.getContext()
const kvManagerConfig = { const kvManagerConfig = {
context: context, context: context,
...@@ -119,27 +118,31 @@ Stage模型下的示例: ...@@ -119,27 +118,31 @@ Stage模型下的示例:
import AbilityStage from '@ohos.application.Ability' import AbilityStage from '@ohos.application.Ability'
let kvManager; let kvManager;
export default class MyAbilityStage extends AbilityStage { export default class MyAbilityStage extends AbilityStage {
onCreate() { onCreate() {
console.log("MyAbilityStage onCreate") console.log("MyAbilityStage onCreate")
let context = this.context let context = this.context
const kvManagerConfig = { const kvManagerConfig = {
context: context, context: context,
bundleName: 'com.example.datamanagertest', bundleName: 'com.example.datamanagertest',
userInfo: { userInfo: {
userId: '0', userId: '0',
userType: distributedData.UserType.SAME_USER_ID userType: distributedData.UserType.SAME_USER_ID
} }
}
distributedData.createKVManager(kvManagerConfig).then((manager) => {
console.log("Succeeded in creating KVManager");
kvManager = manager;
}).catch((err) => {
console.log("Failed to create KVManager: " + JSON.stringify(err));
});
} }
distributedData.createKVManager(kvManagerConfig); }
}
}
``` ```
FA模型下的示例: FA模型下的示例:
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
let kvManager; let kvManager;
console.log("MyAbilityStage onCreate")
let context = featureAbility.getContext() let context = featureAbility.getContext()
const kvManagerConfig = { const kvManagerConfig = {
context: context, context: context,
...@@ -149,7 +152,12 @@ const kvManagerConfig = { ...@@ -149,7 +152,12 @@ const kvManagerConfig = {
userType: distributedData.UserType.SAME_USER_ID userType: distributedData.UserType.SAME_USER_ID
} }
} }
distributedData.createKVManager(kvManagerConfig); distributedData.createKVManager(kvManagerConfig).then((manager) => {
console.log("Succeeded in creating KVManager");
kvManager = manager;
}).catch((err) => {
console.log("Failed to create KVManager: " + JSON.stringify(err));
});
``` ```
## KVManagerConfig ## KVManagerConfig
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册