提交 517e4e9e 编写于 作者: H HuangXW

ServiceExtensionAbility开发指导错误示例代码修改

Signed-off-by: NHuangXW <huangxinwei4@huawei.com>
上级 d429c717
...@@ -42,31 +42,34 @@ OpenHarmony当前不支持三方应用创建ServiceExtensionAbility。 ...@@ -42,31 +42,34 @@ OpenHarmony当前不支持三方应用创建ServiceExtensionAbility。
2. 开发者在定义Service的目录下创建TS文件,自定义类继承ServiceExtensionAbility,重写基类回调函数,示例如下: 2. 开发者在定义Service的目录下创建TS文件,自定义类继承ServiceExtensionAbility,重写基类回调函数,示例如下:
```js ```js
import ServiceExtensionAbility from '@ohos.application.ServiceExtensionAbility'
import rpc from '@ohos.rpc' import rpc from '@ohos.rpc'
class StubTest extends rpc.RemoteObject { class StubTest extends rpc.RemoteObject {
constructor(des) { constructor(des) {
super(des); super(des);
} }
onRemoteRequest(code, data, reply, option) { onRemoteRequest(code, data, reply, option) {
} }
} }
class ServiceExt extends ServiceExtensionAbility { class ServiceExtAbility extends ServiceExtensionAbility {
console.log('onCreate, want:' + want.abilityName); onCreate(want) {
} console.log('onCreate, want:' + want.abilityName);
onRequest(want, startId) { }
console.log('onRequest, want:' + want.abilityName); onRequest(want, startId) {
} console.log('onRequest, want:' + want.abilityName);
onConnect(want) { }
console.log('onConnect , want:' + want.abilityName); onConnect(want) {
return new StubTest("test"); console.log('onConnect , want:' + want.abilityName);
} return new StubTest("test");
onDisconnect(want) { }
console.log('onDisconnect, want:' + want.abilityName); onDisconnect(want) {
} console.log('onDisconnect, want:' + want.abilityName);
onDestroy() { }
console.log('onDestroy'); onDestroy() {
} console.log('onDestroy');
}
} }
``` ```
## 相关实例 ## 相关实例
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册