提交 9beebf26 编写于 作者: Y yuyaozhi

Fix sample code of ability

Signed-off-by: Nyuyaozhi <yuyaozhi@huawei.com>
上级 3ff5b0a7
......@@ -73,29 +73,32 @@ import Want from '@ohos.application.Want';
- 传递RemoteObject数据
``` js
import rpc from '@ohos.rpc';
import Ability from '@ohos.application.Ability'
class Stub extends rpc.RemoteObject {
constructor(des) {
if (typeof des == 'string') {
super(des);
} else {
return null;
}
}
onRemoteRequest(code, data, reply, option) {
if (code === 1) {
console.log('onRemoteRequest called')
let token = data.readInterfaceToken();
let num = data.readInt();
this.method();
return true;
}
return false;
}
method() {
console.log('method called');
}
constructor(des) {
if (typeof des == 'string') {
super(des);
} else {
return null;
}
}
onRemoteRequest(code, data, reply, option) {
if (code === 1) {
console.log('onRemoteRequest called')
let token = data.readInterfaceToken();
let num = data.readInt();
this.method();
return true;
}
return false;
}
method() {
console.log('method called');
}
}
var remoteObject = new Stub('want-test');
......@@ -103,15 +106,17 @@ import Want from '@ohos.application.Want';
"deviceId": "", // deviceId为空表示本设备
"bundleName": "com.extreme.test",
"abilityName": "MainAbility",
"moduleName": "entry" // moduleName非必选
"moduleName": "entry", // moduleName非必选
"parameters": {
"keyRemoteObject":{"type":"RemoteObject", "value":remoteObject}
"keyRemoteObject":{"type":"RemoteObject", "value":remoteObject}
}
};
this.context.startAbility(want, (error) => {
// 显式拉起Ability,通过bundleName、abilityName和moduleName可以唯一确定一个Ability
console.log("error.code = " + error.code)
})
```
<!--no_check-->
......
......@@ -33,14 +33,8 @@ var observer = {
console.log('onUnhandledException, errorMsg: ', errorMsg)
}
}
errorManager.registerErrorObserver(observer)
.then((data) => {
console.log('----------- registerErrorObserver success ----------', data);
})
.catch((err) => {
console.log('----------- registerErrorObserver fail ----------', err);
})
const registerErrorObserverNumber=errorManager.registerErrorObserver(observer)
console.info(registerErrorObserverNumber)
```
## ErrorManager.unregisterErrorObserver
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册