12.鸿蒙HarmonyOS App(JAVA) page的隐式跳转

跳转到指定Page的指定AbilitySlice

复制代码
MainAbilitySlice按钮触发事件:

btn.setClickedListener(component -> {

Intent _intent = new Intent();

Operation operation = new Intent.OperationBuilder()

.withBundleName( getBundleName())

.withAction(SecondPageAbility.ACTION_TARGET)

.withAbilityName(SecondPageAbility.class.getName())

.build();

_intent.setOperation(operation);

startAbility(_intent);

});

复制代码
package com.example.myapplication3.slice;

import com.example.myapplication3.ResourceTable;
import com.example.myapplication3.SecondPageAbility;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.utils.IntentConstants;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        Text text = (Text) findComponentById(ResourceTable.Id_text_main);
        Button btn = (Button) findComponentById(ResourceTable.Id_btn_main);
        text.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent _intent = new Intent();

                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")

                        .withBundleName(getBundleName())

                        .withAbilityName(SecondPageAbility.class.getName())
                      //  .withAction(SecondPageAbility.ACTION_TARGET)
                        .build();
                _intent.setOperation(operation);
             //   _intent.setAction(SecondPageAbility.ACTION_TARGET);

                startAbility(_intent);
            }
        });
        btn.setClickedListener(component -> {
            Intent _intent = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withBundleName( getBundleName())
                    .withAction(SecondPageAbility.ACTION_TARGET)
                    .withAbilityName(SecondPageAbility.class.getName())

                    .build();
            _intent.setOperation(operation);


            startAbility(_intent);
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
复制代码
SecondPageAbility设置actionRoute
复制代码
package com.example.myapplication3;

import com.example.myapplication3.slice.SecondPageAbilitySlice;
import com.example.myapplication3.slice.TargetAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;

public class SecondPageAbility extends Ability {
    public static final String ACTION_TARGET = "action.intent.target_ability_slice";
    public static final String ACTION_Second = "action.intent.second_ability_slice";

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(SecondPageAbilitySlice.class.getName());
       // super.addActionRoute(ACTION_Second, SecondPageAbilitySlice.class.getName());
        super.addActionRoute(ACTION_TARGET, TargetAbilitySlice.class.getName());
       // super.addActionRoute("action.intent.target_ability_slice", TargetAbilitySlice.class.getName());

    }
}

config.json添加,skills/actions

capsule_btn_element.xml

复制代码
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"
       ohos:shape="rectangle">
    <corners
        ohos:radius="100"/>
    <solid
        ohos:color="#007CFD"/>
</shape>

按钮样式的使用方法:

工程代码:

https://download.csdn.net/download/txwtech/88658909?spm=1001.2014.3001.5501https://download.csdn.net/download/txwtech/88658909?spm=1001.2014.3001.5501

相关推荐
kangyouwei8 小时前
鸿蒙开发:19-本地开发配置bash环境执行hvigorw命令
前端·harmonyos
爱笑的眼睛118 小时前
HarmonyOS 应用开发:系统权限申请与管理深度解析
华为·harmonyos
DIY机器人工房10 小时前
科普:华为星闪是什么?华为星闪(英文名 NearLink)是国际星闪无线短距通信联盟发布的新型无线短距通信标准技术。
stm32·嵌入式硬件·华为·嵌入式·diy机器人工房·嵌入式面试题
天黑请闭眼10 小时前
华为对象存储:nginx代理临时访问地址后访问报错:Authentication Failed
nginx·华为
熊猫钓鱼>_>21 小时前
鸿蒙ArkUI基础组件开发详解
华为·harmonyos
猫林老师1 天前
Flutter for HarmonyOS开发指南(八):国际化与本地化深度实践
flutter·华为·harmonyos
夏文强1 天前
HarmonyOS开发-ArkWeb开发指导
华为·harmonyos
Georgewu1 天前
【HarmonyOS 6】SpeechKit中的朗读控件,初始化前不进行窗口舞台的设置,也不会报错,与文档描述不符。
harmonyos
Georgewu1 天前
【HarmonyOS 6】静态和动态添加应用快捷方式详解
harmonyos
爱笑的眼睛111 天前
HarmonyOS preview 预览文件 Kit 的入门讲解(配套后端代码)
华为·harmonyos