不同 Slice 间跳转,同一个 Ability 中,优点是方便,高效,缺点是业务逻辑复杂度受限。
使用 Intent 借助于 ElementName,最常用的页面跳转方式,方便传递参数以及实现相对复杂的业务逻辑交互。
借助于 Operation,可实现跨应用页面跳转。
Rout 路由(JS),调用 router.push() 接口将 uri 指定的页面添加到路由栈中,即跳转到 uri 指定的页面。在调用 router 方法之前,需要导入 router 模块。
调用 router.push() 路由到详情页:
调用 router.back() 回到首页:
通过迁移实现分布式设备间页面传递(有请求迁移和请求回迁两种操作)。
1)需实现 IAbilityContinuation 接口
2)需要权限:
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)。
专注开源技术,共建鸿蒙生态