鸿蒙OS系统中要怎么实现页面跳转?鸿蒙OS中实现页面跳转方法汇总!
时间:2022-08-01 20:31:04
鸿蒙OS系统中要怎么实现页面跳转?鸿蒙系统作为一个开源的免费系统,目前已经开始内部测试使用了。而对于开发人员来说,想要了解鸿蒙的页面跳转方法,下面小编就为大家讲解一下吧!
操作方法:
①不同 Slice 间跳转,同一个 Ability 中,优点是方便,高效,缺点是业务逻辑复杂度受限。
button.setClickedListener(
listener -> present(new SecondAbilitySlice(), new Intent()));
②使用 Intent 借助于 ElementName,最常用的页面跳转方式,方便传递参数以及实现相对复杂的业务逻辑交互。
ElementName elementName = new ElementName(……);
intent.setElement(elementName);
intent.setParam(……);
startAbility(intent);
③借助于 Operation,可实现跨应用页面跳转。
Intent intent = new Intent();
Operation operation = new Intent.OperationBuilder()
.withDeviceId(“”)
.withBundleName(“com.demoapp”)
.withAbilityName(“com.demoapp.FooAbility”)
.build(); intent.setOperation(operation);
startAbility(intent);
④Rout 路由(JS),调用 router.push() 接口将 uri 指定的页面添加到路由栈中,即跳转到 uri 指定的页面。在调用 router 方法之前,需要导入 router 模块。
调用 router.push() 路由到详情页:
// index.js
import router from ‘@system.router’;
export default {
launch() {
router.push ({
uri: ‘pages/detail/detail’, }); },}
调用 router.back() 回到首页:
// detail.js
import router from ‘@system.router’;
export default {
launch() {
router.back(); },}
⑤通过迁移实现分布式设备间页面传递(有请求迁移和请求回迁两种操作)。
1)需实现 IAbilityContinuation 接口
2)需要权限:
ohos.permission.GET_DISTRIBUTED_DEVICE_INFO:用于允许获取分布式组网内的设备列表和设备信息
ohos.permission.DISTRIBUTED_DATASYNC:用于允许不同设备间的数据交换ohos.permission.DISTRIBUTED_DEVICE_STATE_CHANGE:用于允许监听分布式组网内的设备状态变化
ohos.permission.READ_USER_STORAGE:读取存储卡中的内容
ohos.permission.WRITE_USER_STORAGE:修改或删除存储卡中的内容
ohos.permission.GET_BUNDLE_INFO:用于查询其他应用的信息
ohos.permission.servicebus.ACCESS_SERVICE:分布式数据传输的权限
com.huawei.hwddmp.servicebus.BIND_SERVICE:系统应用使用权限
3)需要获取分布式设备 ID(NetworkID)
核心服务类:IContinuationRegisterManager。
服务类的常用 API 方法:
getContinuationRegisterManager();获取服务类的对象
register();注册服务
showDeviceList();获取设备列表
unregister();注销服务
4)请求迁移关键步骤(假定设备 A 向设备 B 迁移)
如下:
需要迁移的 page 实现 IAbilityContinuation 接口
复写 onStartContinuation() 方法,做迁移前的准备工作
复写 onSaveData()方法,保存迁移数据
在设备 B 上复写 onRestoreData() 方法,恢复迁移数据
在设备 A 上复写 onCompleteContinuation() 方法,做迁移后的收尾工作
调用 continueAbility() 或 continueAbilityReversibly() 发起迁移
5)请求回迁需在设备 A 上调用 reverseContinueAbility() 请求回迁
以下关键步骤类似 4)。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
新版win11安装如何跳过联网?Win11跳过联网安装教程
![](https://img.aspxhome.com/file/2023/1/a273551_0s.jpg)
在汇总行上方插入新行后为什么Excel不能自动更新求和公式
win7系统中隐藏administrator帐户的详细步骤
![](https://img.aspxhome.com/file/2023/4/a311661_0s.png)
Win10hello指纹设置不了怎么办?Win10hello指纹设置不了的解决方法
![](https://img.aspxhome.com/file/2023/26/a219838_0s.jpg)
Win7网络感叹号如何解决?
![](https://img.aspxhome.com/file/2023/26/a228726_0s.png)
Win10无线网络连接上但上不了网怎么办?
![](https://img.aspxhome.com/file/2023/26/a221278_0s.jpg)
windows系统资料共享之后如何切换用户问题解决方法
Win10系统怎么设置图片的默认打开方式?
![](https://img.aspxhome.com/file/2023/26/a219524_0s.jpg)
Countif函数怎么使用
![](https://img.aspxhome.com/file/2023/8/a184348_0s.gif)
Mac系统怎么设置隐藏和显示文件或文件夹?
![](https://img.aspxhome.com/file/2023/7/a215097_0s.jpg)
win10重建索引设置教程
![](https://img.aspxhome.com/file/2023/30/a266093_0s.png)
Win10聚焦锁屏壁纸不能自动更换怎么办?
![](https://img.aspxhome.com/file/2023/29/a262332_0s.jpg)
Pdf文档怎么添加超链接? Pdf添加另一个文件超链接的教程
![](https://img.aspxhome.com/file/2023/0/15340_0s.jpg)
Win7开启“防止媒体共享”功能的方法
![](https://img.aspxhome.com/file/2023/27/a232601_0s.jpg)
excel 如何将不同工作表的表格快速打印在一张A4纸上
![](https://img.aspxhome.com/file/2023/8/a155228_0s.png)
iOS16.2 Beta3更新内容及升级建议
![](https://img.aspxhome.com/file/2023/2/44922_0s.png)
建议升级 iOS 13.1.1 正式版:解决耗电异常与键盘安全问题
![](https://img.aspxhome.com/file/2023/3/a196723_0s.jpg)
Win10使用PE还原系统失败报错“19010”的解决办法
![](https://img.aspxhome.com/file/2023/26/a225870_0s.jpg)
Win7无线网络共享设置示例教程
![](https://img.aspxhome.com/file/2023/29/a257645_0s.jpg)
Win10突然重启后怎么恢复之前运行的窗口和程序?
![](https://img.aspxhome.com/file/2023/28/a242270_0s.jpg)