Harmony在AbilitySlice之间导航

实现了同一个PageAbility内部不同AbilitySlice之间的导航.

首先新建一个AbilitySlice2,将其加入MainAblity:

addActionRoute("my.action", AbilitySlice2.class.getName());

在config.json中配置动作:

            "actions": [
              "action.system.home",
              "my.action"
            ]

实现MainAbilitySlice中的按钮点击方法导航到AbilitySlice2:

    private void initLayout(){
        txt = (Text) findComponentById(ResourceTable.Id_text1);
        btn = (Button) findComponentById(ResourceTable.Id_button1);
        btn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                presentForResult(new AbilitySlice2(), new Intent(), 0);
            }
        });
    }

实现AbilitySlice2中的按钮点击方法返回结果:

    private void initLayout(){
        btn = (Button) findComponentById(ResourceTable.Id_button2);
        btn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent resIntent = new Intent();
                setResult(resIntent);
                terminate();
            }
        });
posted @ 2024-04-28 17:40  MSTK  阅读(7)  评论(0编辑  收藏  举报