1、一个app下创建多个module,moudule之间的跳转
如下图,一个app下有多个module,一个是entry,最为程序的主入口;一个是myFirstMoudle,它的Moudule type是 feature(特征)
二、一个手机内的多个app之间的跳转
三、实现代码如下
二、系统内应用相互跳转和同一个app的多个module之间跳转
// ①跳转相册 —— 系统应用
let want = {
"deviceId": "",
"bundleName": "",
"abilityName": "",
"uri": "",
"type": "image/*",
"action": "android.intent.action.GET_CONTENT",
"parameters": {},
"entities": []
}
// ②跳转系统设置无障碍 —— 系统应用
let want = {
"deviceId": "",
"bundleName": "",
"abilityName": "",
"uri": "",
"action": "android.settings.ACCESSIBILITY_SETTINGS",
"parameters": {},
"entities": []
}
this.context.startAbility(want, (err) => {
if (err.code) {
// 处理业务逻辑错误
console.log('startAbility failed, error.code: ' + JSON.stringify(err.code) +
' error.message: ' + JSON.stringify(err.message));
return;
}
// 正常逻辑
})
// ③系统内置的 Action 参数
import wantConstant from '@ohos.ability.wantConstant';
// 打开系统设置的另一种方式(使用 HarmonOS 内置的枚举) —— 系统应用
let want = {
"deviceId": "",
"bundleName": "",
"abilityName": "",
"uri": "",
"action": wantConstant.Action.ACTION_WIRELESS_SETTINGS,
"parameters": {},
"entities": []
}
// ④ A UIAbility 和 A-1 UIAbility (A 的 Feature UIAbility,作为子 module 存在),需求是我们要实现 entry 跳转到 feature UIAbility
// 这个跳转自定义的module或者app
if (item.id === 1001){
want.bundleName = "com.examples";
want.abilityName = "FeatTestNotificationAbility";
want.moduleName ="featTestNotification";
want.action = null;
}
this.context.startAbility(want, (err) => {
if (err.code) {
// 处理业务逻辑错误
console.log('startAbility failed, error.code: ' + JSON.stringify(err.code) +
' error.message: ' + JSON.stringify(err.message));
return;
}
// 正常逻辑
})
三、如果看不懂上面的代码,请阅读官方文档,UIAbility组件概述,want参数配置,上下文获取
四、同一个moudle内的page页面跳转
在应用内之前实现不同 page 的跳转,我们使用 router
即可,页面跳转主要支持如下两个方法:
- router.pushUrl():目标页不会替换当前页,而是压入页面栈。这样可以保留当前页的状态,并且可以通过返回键或者调用router.back()方法返回到当前页。
- router.replaceUrl():目标页会替换当前页,并销毁当前页。这样可以释放当前页的资源,并且无法返回到当前页。
router 跳转模式
- Standard:标准实例模式,也是默认情况下的实例模式。每次调用该方法都会新建一个目标页,并压入栈顶。
- Single:单实例模式。即如果目标页的url在页面栈中已经存在同url页面,则离栈顶最近的同url页面会被移动到栈顶,并重新加载;如果目标页的url在页面栈中不存在同url页面,则按照标准模式跳转。