HarmonyOS 5.0 应用开发——UIAbility 跳转

【高心星出品】
UIAbility 跳转
UIAbility 是系统调度的最小单元。在设备内的功能模块之间跳转时,会涉及到启动特定的 UIAbility,包括应用内的其他 UIAbility、或者其他应用的 UIAbility(例如启动三方支付 UIAbility)。
发起跳转
以下的案例将要实现:EntryAbility 加载的 index 页面中文本,点击之后跳转到 EntryAbility1 加载的 index1 页面中。
可以在后台看到两个任务窗口。

index 页面代码
Ability 的启动模式
UIAbility 的启动模式是指 UIAbility 实例在启动时的不同呈现状态。针对不同的业务场景,系统提供了三种启动模式:
singleton(单实例模式)
multiton(多实例模式)
specified(指定实例模式)
在这里我们只介绍前两种常用启动模式。
singleton 启动模式
singleton 启动模式为单实例模式,也是默认情况下的启动模式。
每次调用 startAbility()方法时,如果应用进程中该类型的 UIAbility 实例已经存在,则复用系统中的 UIAbility 实例。系统中只存在唯一一个该 UIAbility 实例,即在最近任务列表中只存在一个该类型的 UIAbility 实例。
生命周期函数调用顺序:startAbility(EntryAbility)----》onNewWant()(EntryAbility1)不会执行 oncrate。

需要在 module.json5 配置单例启动模式。
multiton 启动模式
multiton 启动模式为多实例模式,每次调用 startAbility()方法时,都会在应用进程中创建一个新的该类型 UIAbility 实例。即在最近任务列表中可以看到有多个该类型的 UIAbility 实例。这种情况下可以将 UIAbility 配置为 multiton(多实例模式)。
生命周期函数调用顺序:startAbility(EntryAbility)----》oncreate()(EntryAbility1)不会执行 onNewWant()周期函数。

需要在 module.json5 配置多实例启动模式。
版权声明: 本文为 InfoQ 作者【高心星】的原创文章。
原文链接:【http://xie.infoq.cn/article/a5b8dcaf48d784acd04946461】。文章转载请联系作者。
评论