美文网首页
鸿蒙第10课Abilaty页面切换全生命周期(2)

鸿蒙第10课Abilaty页面切换全生命周期(2)

作者: 游私塾白书生 | 来源:发表于2022-06-04 23:07 被阅读0次

1.创建一个页面创建多个

2.在主页面添加其他路由

3.在配置文件中加入路由的名字

4.在创建能力B的页面

5.A的主页面

6.按钮跳转

TextresText;

//        设置返回编码

    private static final int REQURNT_CODE=0x01101;

    @Override

    public void onStart(Intent intent) {

super.onStart(intent);

        super.setUIContent(ResourceTable.Layout_ability_a);

//            获取第一个页面按钮的id

        Button btn=(Button)findComponentById(ResourceTable.Id_pre_btn1);

//            获取第二个文本id

      resText=(Text)findComponentById(ResourceTable.Id_text_helloworld2);

        btn.setClickedListener(component -> {

//1.没有返回结果  也没有带结果的数据跳转过去

//            present(new AAbilitySecondSlice(),new Intent());

            //2.有返回结果  没有带数据跳转过去                          标图来判断

//            presentForResult(new AAbilitySecondSlice(),new Intent(),REQURNT_CODE);

//            3.有返回结果  带数据跳转过去                          标图来判断

            presentForResult(new AAbilitySecondSlice(),new Intent().setParam("user","这是谁"),REQURNT_CODE);

        });

7.返回数据

//        ————————--------------分割

                Button btn2=(Button) findComponentById(ResourceTable.Id_pre_btn2);

                btn2.setClickedListener(component -> {

Intent i=new Intent();

                    Operation operation=new Intent.OperationBuilder()

//                            目标设备  空 表示本设备

                            .withDeviceId("")

//                            隐式跳转

                            .withAction("B_second")

//                            应用App的  BundName的名字

                            .withBundleName(getBundleName())

//                            通过ability的全名  启动某个ability

                            .withAbilityName(BAbility.class.getName())

.build();

                    i.setOperation(operation);

                    startAbility(i);

                });

8.第二个返回按钮

9.第二个切片代码

10.第二个页面

11.

12.

相关文章

网友评论

      本文标题:鸿蒙第10课Abilaty页面切换全生命周期(2)

      本文链接:https://www.haomeiwen.com/subject/niwiprtx.html