中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
1.创建stage模型的项目
2.初始的entryability默认绑定index.ets
3.新建一个Ability与page,并且绑定
4.pages下的Index.ets代码:
import context from '@ohos.application.context'; @Entry @Component struct Index { @State message: string = '第一个Ability的page' build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) Button("CLICKME") .onClick(this.explicitStartAbility) } .width('100%') } .height('100%') } async explicitStartAbility() { try { let want = { deviceId: "", bundleName: "com.example.want_demo", abilityName: "EntryAbility1" }; let context = getContext(this) as context.AbilityContext; await context.startAbility(want); console.info(`explicit start ability succeed`); } catch (err) { console.info(`explicit start ability failed with ` + err.code); } } }
pages下的Page.ets代码:
@Entry @Component struct Page { @State message: string = '第二个Ability的page' build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) } .width('100%') } .height('100%') } }
5.打开模拟器浏览演示
微信扫码分享