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

相关推荐
凯子坚持 c2 小时前
解锁仓颉编程语言的奥秘:枚举类型、模式匹配与类接口全解析
开发语言·华为·harmonyos
JasonYin~2 小时前
HarmonyOS NEXT 实战之元服务:静态案例效果---电动车助手
harmonyos
傻啦嘿哟3 小时前
华为原生鸿蒙5.0与代理IP的奇妙融合
tcp/ip·华为·harmonyos
JiaWen技术圈3 小时前
HuaWei、NVIDIA 数据中心 AI 算力对比
人工智能·华为·gpu算力·英伟达
JasonYin~7 小时前
HarmonyOS NEXT 实战之元服务:静态案例效果--- 手机一键加速、手机垃圾清理
华为·harmonyos
Freerain9913 小时前
鸿蒙Next类属性观测器V2
华为·harmonyos
yg_小小程序员15 小时前
鸿蒙开发(16)使用DevEco Studio上的Git工具进行多远程仓管理
git·华为·harmonyos
JasonYin~15 小时前
HarmonyOS NEXT 实战之元服务:静态案例效果---每日玩机技巧
harmonyos
轻口味15 小时前
【每日学点鸿蒙知识】多线程限制、axios组件下载进度问题、lpx问题、Web组件全局代理、ArrayList问题
华为·harmonyos
yuanlaile15 小时前
纯Dart Flutter库适配HarmonyOS
flutter·华为·harmonyos·flutter开发鸿蒙·harmonyos教程