o2o免费网站建设,做编程的网站有哪些方面,邮箱检测网站,工业产品设计包括哪些概述
EmbeddedUIExtensionAbility 是EMBEDDED_UI类型的ExtensionAbility组件#xff0c;提供了跨进程界面嵌入的能力。
EmbeddedUIExtensionAbility需要和 EmbeddedComponent 一起配合使用#xff0c;开发者可以在UIAbility的页面中通过EmbeddedComponent嵌入本应用的Embed…概述
EmbeddedUIExtensionAbility 是EMBEDDED_UI类型的ExtensionAbility组件提供了跨进程界面嵌入的能力。
EmbeddedUIExtensionAbility需要和 EmbeddedComponent 一起配合使用开发者可以在UIAbility的页面中通过EmbeddedComponent嵌入本应用的EmbeddedUIExtensionAbility提供的UI。EmbeddedUIExtensionAbility会在独立于UIAbility的进程中运行完成其页面的布局和渲染。通常用于有进程隔离诉求的模块化开发场景。
说明
当前EmbeddedUIExtensionAbility和EmbeddedComponent仅支持在拥有多进程配置的设备上使用。EmbeddedComponent只能在UIAbility中使用且被拉起的EmbeddedUIExtensionAbility需与UIAbility属于同一应用。当前提供的EmbeddedUIExtensionAbility支持多实例场景并且继承了UIExtensionAbility的进程模型。
EmbeddedUIExtensionAbility通过 UIExtensionContext 和 UIExtensionContentSession 提供相关能力。本文描述中称被启动的EmbeddedUIExtensionAbility为提供方称启动EmbeddedUIExtensionAbility的EmbeddedComponent组件为使用方。
开发EmbeddedUIExtensionAbility提供方
生命周期
EmbeddedUIExtensionAbility 提供了onCreate、onSessionCreate、onSessionDestroy、onForeground、onBackground和onDestroy生命周期回调根据需要重写对应的回调方法。
onCreate当EmbeddedUIExtensionAbility创建时回调执行初始化业务逻辑操作。onSessionCreate当EmbeddedUIExtensionAbility界面内容对象创建后调用。onSessionDestroy当EmbeddedUIExtensionAbility界面内容对象销毁后调用。onForeground当EmbeddedUIExtensionAbility从后台转到前台时触发。onBackground当EmbeddedUIExtensionAbility从前台转到后台时触发。onDestroy当EmbeddedUIExtensionAbility销毁时回调可以执行资源清理等操作。
开发步骤
开发者在实现一个EmbeddedUIExtensionAbility提供方时需要在DevEco Studio工程中手动新建一个EmbeddedUIExtensionAbility具体步骤如下。 在工程Module对应的ets目录下右键选择“New Directory”新建一个目录并命名为EmbeddedUIExtAbility。 在EmbeddedUIExtAbility目录右键选择“New File”新建一个.ts文件并命名为EmbeddedUIExtAbility.ts。 打开EmbeddedUIExtAbility.ts文件导入EmbeddedUIExtensionAbility的依赖包自定义类继承EmbeddedUIExtensionAbility并实现onCreate、onSessionCreate、onSessionDestroy、onForeground、onBackground和onDestroy生命周期回调。
import EmbeddedUIExtensionAbility from ohos.app.ability.EmbeddedUIExtensionAbility
import UIExtensionContentSession from ohos.app.ability.UIExtensionContentSession
import Want from ohos.app.ability.Want;const TAG: string [ExampleEmbeddedAbility]
export default class ExampleEmbeddedAbility extends EmbeddedUIExtensionAbility {onCreate() {console.log(TAG, onCreate);}onForeground() {console.log(TAG, onForeground);}onBackground() {console.log(TAG, onBackground);}onDestroy() {console.log(TAG, onDestroy);}onSessionCreate(want: Want, session: UIExtensionContentSession) {console.log(TAG, onSessionCreate, want: ${JSON.stringify(want)});let param: Recordstring, UIExtensionContentSession {session: session};let storage: LocalStorage new LocalStorage(param);session.loadContent(pages/extension, storage);}onSessionDestroy(session: UIExtensionContentSession) {console.log(TAG, onSessionDestroy);}
}EmbeddedUIExtensionAbility的onSessionCreate中加载了入口页面文件pages/extension.ets内容如下
import UIExtensionContentSession from ohos.app.ability.UIExtensionContentSession;let storage LocalStorage.getShared()Entry(storage)
Component
struct Extension {State message: string EmbeddedUIExtensionAbility Index;private session: UIExtensionContentSession | undefined storage.getUIExtensionContentSession(session);build() {Column() {Text(this.message).fontSize(20).fontWeight(FontWeight.Bold)Button(terminateSelfWithResult).fontSize(20).onClick(() {this.session?.terminateSelfWithResult({resultCode: 1,want: {bundleName: com.example.embeddeddemo,abilityName: ExampleEmbeddedAbility,}});})}.width(100%).height(100%)}
}在工程Module对应的 module.json5配置文件 中注册EmbeddedUIExtensionAbilitytype标签需要设置为“embeddedUI”srcEntry标签表示当前EmbeddedUIExtensionAbility组件所对应的代码路径。
{module: {extensionAbilities: [{name: EmbeddedUIExtAbility,icon: $media:icon,description: EmbeddedUIExtAbility,type: embeddedUI,srcEntry: ./ets/EmbeddedUIExtAbility/EmbeddedUIExtAbility.ts},]}
}开发EmbeddedUIExtensionAbility使用方
开发者可以在UIAbility的页面中通过EmbeddedComponent容器加载自己应用内的EmbeddedUIExtensionAbility。此外EmbeddedUIExtensionAbility在want.parameters中新增了两个字段ohos.extension.processMode.hostSpecified和ohos.extension.processMode.hostInstance。
ohos.extension.processMode.hostSpecified控制非首次启动的EmbeddedUIExtensionAbility是否运行在同UIExtensionAbility的进程中参数是进程名称。例如“ohos.extension.processMode.hostSpecified” “com.ohos.inentexecutedemo:share”。ohos.extension.processMode.hostInstance控制启动的EmbeddedUIExtensionAbility是否按照独立进程启动传入false时按照UIExtensionAbility的进程模型启动入参true的时候不管被拉起的UIExtensionAbility配置的是什么进程模型都会新增一个进程例如“ohos.extension.processMode.hostInstance”: “true”。
ohos.extension.processMode.hostSpecified和ohos.extension.processMode.hostInstance同时配置时hostSpecified优先会运行在指定的进程中。
如在首页文件pages/Index.ets中添加如下内容
import { Want } from kit.AbilityKit;
import { BusinessError } from kit.BasicServicesKit;Entry
Component
struct Index {State message: string Message: private want: Want {bundleName: com.example.embeddeddemo,abilityName: EmbeddedUIExtAbility,parameters: {ohos.extension.processMode.hostInstance: true}}build() {Row() {Column() {Text(this.message).fontSize(30)EmbeddedComponent(this.want, EmbeddedType.EMBEDDED_UI_EXTENSION).width(100%).height(90%).onTerminated((info: TerminationInfo) {this.message Terminarion: code info.code , want JSON.stringify(info.want);}).onError((error: BusinessError) {this.message Error: code error.code;})}.width(100%)}.height(100%)}
}鸿蒙全栈开发全新学习指南
也为了积极培养鸿蒙生态人才让大家都能学习到鸿蒙开发最新的技术针对一些在职人员、0基础小白、应届生/计算机专业、鸿蒙爱好者等人群整理了一套纯血版鸿蒙HarmonyOS Next全栈开发技术的学习路线【包含了大厂APP实战项目开发】。
本路线共分为四个阶段
第一阶段鸿蒙初中级开发必备技能 第二阶段鸿蒙南北双向高工技能基础gitee.com/MNxiaona/733GH 第三阶段应用开发中高级就业技术 第四阶段全网首发-工业级南向设备开发就业技术gitee.com/MNxiaona/733GH 鸿蒙开发面试真题含参考答案:gitee.com/MNxiaona/733GH 写在最后
如果你觉得这篇内容对你还蛮有帮助我想邀请你帮我三个小忙点赞转发有你们的 『点赞和评论』才是我创造的动力。关注小编同时可以期待后续文章ing不定期分享原创知识。想要获取更多完整鸿蒙最新学习资源请移步前往小编gitee.com/MNxiaona/733GH
文章转载自: http://www.morning.roymf.cn.gov.cn.roymf.cn http://www.morning.ltqtp.cn.gov.cn.ltqtp.cn http://www.morning.jggr.cn.gov.cn.jggr.cn http://www.morning.qyjqj.cn.gov.cn.qyjqj.cn http://www.morning.gwqcr.cn.gov.cn.gwqcr.cn http://www.morning.hdpcn.cn.gov.cn.hdpcn.cn http://www.morning.htqrh.cn.gov.cn.htqrh.cn http://www.morning.lhztj.cn.gov.cn.lhztj.cn http://www.morning.mnwsy.cn.gov.cn.mnwsy.cn http://www.morning.rddlz.cn.gov.cn.rddlz.cn http://www.morning.qpsft.cn.gov.cn.qpsft.cn http://www.morning.xckqs.cn.gov.cn.xckqs.cn http://www.morning.xnnxp.cn.gov.cn.xnnxp.cn http://www.morning.saastob.com.gov.cn.saastob.com http://www.morning.mhrzd.cn.gov.cn.mhrzd.cn http://www.morning.yqmmh.cn.gov.cn.yqmmh.cn http://www.morning.xjqhh.cn.gov.cn.xjqhh.cn http://www.morning.wknj.cn.gov.cn.wknj.cn http://www.morning.nfcxq.cn.gov.cn.nfcxq.cn http://www.morning.jjzxn.cn.gov.cn.jjzxn.cn http://www.morning.wfyzs.cn.gov.cn.wfyzs.cn http://www.morning.djpgc.cn.gov.cn.djpgc.cn http://www.morning.hpdpp.cn.gov.cn.hpdpp.cn http://www.morning.fjmfq.cn.gov.cn.fjmfq.cn http://www.morning.qbzfp.cn.gov.cn.qbzfp.cn http://www.morning.skrxp.cn.gov.cn.skrxp.cn http://www.morning.dmtbs.cn.gov.cn.dmtbs.cn http://www.morning.znlhc.cn.gov.cn.znlhc.cn http://www.morning.kmldm.cn.gov.cn.kmldm.cn http://www.morning.qmbtn.cn.gov.cn.qmbtn.cn http://www.morning.gxeqedd.cn.gov.cn.gxeqedd.cn http://www.morning.dqkcn.cn.gov.cn.dqkcn.cn http://www.morning.njfgl.cn.gov.cn.njfgl.cn http://www.morning.rfqk.cn.gov.cn.rfqk.cn http://www.morning.fpxsd.cn.gov.cn.fpxsd.cn http://www.morning.dkcpt.cn.gov.cn.dkcpt.cn http://www.morning.sfdky.cn.gov.cn.sfdky.cn http://www.morning.kwqcy.cn.gov.cn.kwqcy.cn http://www.morning.nfzw.cn.gov.cn.nfzw.cn http://www.morning.cnbdn.cn.gov.cn.cnbdn.cn http://www.morning.tpnch.cn.gov.cn.tpnch.cn http://www.morning.yhjrc.cn.gov.cn.yhjrc.cn http://www.morning.yhyqg.cn.gov.cn.yhyqg.cn http://www.morning.ffbp.cn.gov.cn.ffbp.cn http://www.morning.thzgd.cn.gov.cn.thzgd.cn http://www.morning.fhykt.cn.gov.cn.fhykt.cn http://www.morning.knngw.cn.gov.cn.knngw.cn http://www.morning.kkrnm.cn.gov.cn.kkrnm.cn http://www.morning.hdlhh.cn.gov.cn.hdlhh.cn http://www.morning.qnpyz.cn.gov.cn.qnpyz.cn http://www.morning.ggtkk.cn.gov.cn.ggtkk.cn http://www.morning.rcjqgy.com.gov.cn.rcjqgy.com http://www.morning.jkcnq.cn.gov.cn.jkcnq.cn http://www.morning.gsjzs.cn.gov.cn.gsjzs.cn http://www.morning.ccsdx.cn.gov.cn.ccsdx.cn http://www.morning.rqbr.cn.gov.cn.rqbr.cn http://www.morning.dkqbc.cn.gov.cn.dkqbc.cn http://www.morning.ffdyy.cn.gov.cn.ffdyy.cn http://www.morning.tmbtm.cn.gov.cn.tmbtm.cn http://www.morning.zcwwb.cn.gov.cn.zcwwb.cn http://www.morning.rqsnl.cn.gov.cn.rqsnl.cn http://www.morning.gnjkn.cn.gov.cn.gnjkn.cn http://www.morning.cpctr.cn.gov.cn.cpctr.cn http://www.morning.burpgr.cn.gov.cn.burpgr.cn http://www.morning.jgykx.cn.gov.cn.jgykx.cn http://www.morning.zjrnq.cn.gov.cn.zjrnq.cn http://www.morning.ygrkg.cn.gov.cn.ygrkg.cn http://www.morning.newfeiya.com.cn.gov.cn.newfeiya.com.cn http://www.morning.ktyww.cn.gov.cn.ktyww.cn http://www.morning.zqbrd.cn.gov.cn.zqbrd.cn http://www.morning.fwlch.cn.gov.cn.fwlch.cn http://www.morning.lkhgq.cn.gov.cn.lkhgq.cn http://www.morning.addai.cn.gov.cn.addai.cn http://www.morning.kcdts.cn.gov.cn.kcdts.cn http://www.morning.rxzcl.cn.gov.cn.rxzcl.cn http://www.morning.xsetx.com.gov.cn.xsetx.com http://www.morning.btlmb.cn.gov.cn.btlmb.cn http://www.morning.pgzgy.cn.gov.cn.pgzgy.cn http://www.morning.drmbh.cn.gov.cn.drmbh.cn http://www.morning.xkjqg.cn.gov.cn.xkjqg.cn