未验证 提交 e67e20dd 编写于 作者: O openharmony_ci 提交者: Gitee

!16175 资料描述优化

Merge pull request !16175 from mingxihua/master
......@@ -17,6 +17,7 @@ ServiceExtensionContext模块提供ServiceExtensionAbility具有的能力,包
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
let context;
let commRemote; // 断开连接时需要释放
class EntryAbility extends ServiceExtensionAbility {
onCreate() {
context = this.context; // 获取ServiceExtensionContext
......@@ -1093,7 +1094,10 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
abilityName: 'MyAbility'
};
let options = {
onConnect(elementName, remote) { console.log('----------- onConnect -----------') },
onConnect(elementName, remote) {
commRemote = remote;
console.log('----------- onConnect -----------');
},
onDisconnect(elementName) { console.log('----------- onDisconnect -----------') },
onFailed(code) { console.error('----------- onFailed -----------') }
};
......@@ -1154,7 +1158,10 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options
};
let accountId = 100;
let options = {
onConnect(elementName, remote) { console.log('----------- onConnect -----------'); },
onConnect(elementName, remote) {
commRemote = remote;
console.log('----------- onConnect -----------');
},
onDisconnect(elementName) { console.log('----------- onDisconnect -----------'); },
onFailed(code) { console.log('----------- onFailed -----------'); }
};
......@@ -1172,7 +1179,7 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options
disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback<void>): void;
将一个Ability与绑定的服务类型的Ability解绑。
将一个Ability与绑定的服务类型的Ability解绑,断开连接之后需要将连接成功时返回的remote对象置空
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -1204,6 +1211,7 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback<
try {
this.context.disconnectServiceExtensionAbility(connection, (error) => {
commRemote = null;
if (error.code) {
// 处理业务逻辑错误
console.error('disconnectServiceExtensionAbility failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
......@@ -1213,6 +1221,7 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback<
console.log('disconnectServiceExtensionAbility succeed');
});
} catch (paramError) {
commRemote = null;
// 处理入参错误异常
console.error('error.code: ${JSON.stringify(paramError.code)}, error.message: ${JSON.stringify(paramError.message)}');
}
......@@ -1222,7 +1231,7 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback<
disconnectServiceExtensionAbility(connection: number): Promise<void>;
将一个Ability与绑定的服务类型的Ability解绑。通过Promise返回结果
将一个Ability与绑定的服务类型的Ability解绑,断开连接之后需要将连接成功时返回的remote对象置空(Promise形式返回结果)
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -1260,14 +1269,17 @@ disconnectServiceExtensionAbility(connection: number): Promise<void>;
try {
this.context.disconnectServiceExtensionAbility(connection)
.then((data) => {
commRemote = null;
// 执行正常业务
console.log('disconnectServiceExtensionAbility succeed');
})
.catch((error) => {
commRemote = null;
// 处理业务逻辑错误
console.error('disconnectServiceExtensionAbility failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
});
} catch (paramError) {
commRemote = null;
// 处理入参错误异常
console.error('error.code: ${JSON.stringify(paramError.code)}, error.message: ${JSON.stringify(paramError.message)}');
}
......
......@@ -1349,6 +1349,7 @@ let want = {
};
let options = {
onConnect(elementName, remote) {
commRemote = remote;
console.info('onConnect...')
},
onDisconnect(elementName) {
......@@ -1415,6 +1416,7 @@ let want = {
let accountId = 100;
let options = {
onConnect(elementName, remote) {
commRemote = remote;
console.info('onConnect...')
},
onDisconnect(elementName) {
......@@ -1438,7 +1440,7 @@ try {
disconnectServiceExtensionAbility(connection: number): Promise\<void>;
断开与ServiceExtensionAbility的连接(promise形式)。
断开与ServiceExtensionAbility的连接,断开连接之后需要将连接成功时返回的remote对象置空(promise形式)。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -1471,6 +1473,7 @@ let connection = 1;
try {
this.context.disconnectServiceExtensionAbility(connection, (err) => {
commRemote = null;
if (err.code) {
// 处理业务逻辑错误
console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
......@@ -1480,6 +1483,7 @@ try {
console.info('disconnectServiceExtensionAbility succeed');
});
} catch (err) {
commRemote = null;
// 处理入参错误异常
console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
}
......@@ -1489,7 +1493,7 @@ try {
disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback\<void>): void;
断开与ServiceExtensionAbility的连接(callback形式)。
断开与ServiceExtensionAbility的连接,断开连接之后需要将连接成功时返回的remote对象置空(callback形式)。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -1517,6 +1521,7 @@ let connection = 1;
try {
this.context.disconnectServiceExtensionAbility(connection, (err) => {
commRemote = null;
if (err.code) {
// 处理业务逻辑错误
console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
......@@ -1526,6 +1531,7 @@ try {
console.info('disconnectServiceExtensionAbility succeed');
});
} catch (err) {
commRemote = null;
// 处理入参错误异常
console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册