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();
            }
        });
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章