赞
踩
修改方式:entry ability下module.json5文件中添加或修改这句话
- //Singleton模式:每一个UIAbility只存在唯一实例,是默认实例,任务列表中只有一个。
- "launchType":"Singleton",
- //multiton模式:每次启动UIAbility都会创建一个新的实例,任务列表中只有一个。
- "launchType":"multiton",
- //standard模式:每次启动UIAbility都会创建一个新的实例,任务列表中存在一个或者多个。
- "launchType":"standard",
- //specified模式:每个UIAbility可以设置key标示,启动UIAbility时,需要指定key,存在key相同实例直接被拉起,不存在则创建新实例
- "launchType":"specified",
- //1.准备一个context
- private context = getContext(this) as common.UIAbilityContext
-
- //2.跳转的目的地want
- let want: Want = {
- deviceId: '', //空表示当前应用
- bundleName: 'com.example.myapplication',//在app.json5中
- moduleName: 'entry', //模块名
- abilityName: 'DocumentAbility', //跳转的目的Ability名
- parameters: {
- instanceKey: 'idx_' + this.index++ //设置唯一的key
- }
- }
-
- //3.跳转
- this.context.startAbility(want)

- import AbilityStage from '@ohos.app.ability.AbilityStage';
- import Want from '@ohos.app.ability.Want';
- export default class MyAbilityStage extends AbilityStage{
- onAcceptWant(want:Want):string {
- if(want.abilityName === 'DocumentAbility'){
- return `DocAbilityInstanse_${want.parameters.instanceKey}`
- }
- return ''
- }
- }
- //一般在"name": "entry","type": "entry",下面配置
- "srcEntry": './ets/myabilitystage/MyAbilityStage.ts',
- //1.获取context
- private context = getContext(this) as common.UIAbilityContext
- //2.跳转到文档列表的 UIAbility
- let want: Want = {
- deviceId: '',
- bundleName: 'com.example.myapplication',
- moduleName: 'entry',
- abilityName: 'EntryAbility'
- //因为跳回去的EntryAbility是单实例模式,所以不需要指定key
- }
- //3.跳转
- this.context.startAbility(want)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。