提交 271f01e0 编写于 作者: Y yanwenhao

Move demo of attribute parameter from dev guide to API reference

Signed-off-by: Nyanwenhao <yanwenhao9@huawei.com>
Change-Id: Ife054318ddc06d9dcdd011aec0530576a122ad49
上级 dc074931
......@@ -46,9 +46,69 @@ import Want from '@ohos.application.Want';
})
```
- 传递FD数据,FD表示文件描述符(FileDescriptor)
``` js
- 通过自定字段传递数据, 以下为当前支持类型。
* 字符串(String)
```ts
let want = {
bundleName: "com.example.demo",
abilityName: "com.example.demo.MainAbility",
parameters: {
keyForString: "str",
},
}
```
* 数字(Number)
```ts
let want = {
bundleName: "com.example.demo",
abilityName: "com.example.demo.MainAbility",
parameters: {
keyForInt: 100,
keyForDouble: 99.99,
},
}
```
* 布尔(Boolean)
```ts
let want = {
bundleName: "com.example.demo",
abilityName: "com.example.demo.MainAbility",
parameters: {
keyForBool: true,
},
}
```
* 对象(Object)
```ts
let want = {
bundleName: "com.example.demo",
abilityName: "com.example.demo.MainAbility",
parameters: {
keyForObject: {
keyForObjectString: "str",
keyForObjectInt: -200,
keyForObjectDouble: 35.5,
keyForObjectBool: false,
},
},
}
```
* 数组(Array)
```ts
let want = {
bundleName: "com.example.demo",
abilityName: "com.example.demo.MainAbility",
parameters: {
keyForArrayString: ["str1", "str2", "str3"],
keyForArrayInt: [100, 200, 300, 400],
keyForArrayDouble: [0.1, 0.2],
keyForArrayObject: [{obj1: "aaa"}, {obj2: 100}],
},
}
```
* 文件描述符(FD)
```ts
import fileio from '@ohos.fileio';
var fd;
try {
......@@ -71,54 +131,6 @@ 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');
}
}
var remoteObject = new Stub('want-test');
var want = {
"deviceId": "", // deviceId为空表示本设备
"bundleName": "com.extreme.test",
"abilityName": "MainAbility",
"moduleName": "entry", // moduleName非必选
"parameters": {
"keyRemoteObject":{"type":"RemoteObject", "value":remoteObject}
}
};
this.context.startAbility(want, (error) => {
// 显式拉起Ability,通过bundleName、abilityName和moduleName可以唯一确定一个Ability
console.log("error.code = " + error.code)
})
```
<!--no_check-->
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册