diff --git a/zh-cn/application-dev/application-models/create-serviceability.md b/zh-cn/application-dev/application-models/create-serviceability.md index 10e961ed9946aa14538064b6055697a7b6589e90..2fb1b03cc53a166951c620ff31986a9fd5652a95 100644 --- a/zh-cn/application-dev/application-models/create-serviceability.md +++ b/zh-cn/application-dev/application-models/create-serviceability.md @@ -3,43 +3,43 @@ 1. 创建ServiceAbility。 - 重写ServiceAbility的生命周期方法,添加其他Ability请求与ServiceAbility交互时的处理方法。 + 重写ServiceAbility的生命周期方法,添加其他Ability请求与ServiceAbility交互时的处理方法。 - ```ts - import rpc from "@ohos.rpc" - - class FirstServiceAbilityStub extends rpc.RemoteObject { - constructor(des: any) { - if (typeof des === 'string') { - super(des) - } else { - return - } - } - } - - export default { - onStart() { - console.info('ServiceAbility onStart') - }, - onStop() { - console.info('ServiceAbility onStop') - }, - onCommand(want, startId) { - console.info('ServiceAbility onCommand') - }, - onConnect(want) { - console.info('ServiceAbility onConnect' + want) - return new FirstServiceAbilityStub('test') - }, - onDisconnect(want) { - console.info('ServiceAbility onDisconnect' + want) - } - } - ``` + ```ts + import rpc from "@ohos.rpc" + + class FirstServiceAbilityStub extends rpc.RemoteObject { + constructor(des: any) { + if (typeof des === 'string') { + super(des) + } else { + return + } + } + } + + export default { + onStart() { + console.info('ServiceAbility onStart') + }, + onStop() { + console.info('ServiceAbility onStop') + }, + onCommand(want, startId) { + console.info('ServiceAbility onCommand') + }, + onConnect(want) { + console.info('ServiceAbility onConnect' + want) + return new FirstServiceAbilityStub('test') + }, + onDisconnect(want) { + console.info('ServiceAbility onDisconnect' + want) + } + } + ``` 2. 注册ServiceAbility。 - + ServiceAbility需要在应用配置文件config.json中进行注册,注册类型type需要设置为service。"visible"属性表示ServiceAbility是否可以被其他应用调用,true表示可以被其他应用调用,false表示不能被其他应用调用(仅应用内可以调用)。若ServiceAbility需要被其他应用调用,注册ServiceAbility时需要设置"visible"为true,同时需要设置支持关联启动。ServiceAbility的启动规则详见[组件启动规则](component-startup-rules.md)章节。 ```json