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

相关推荐
jiejiejiejie_20 小时前
Flutter for OpenHarmony 心情日记功能实战指南
flutter·华为
Math_teacher_fan1 天前
Flutter 跨平台开发实战:鸿蒙与音乐律动艺术(六)、Lissajous 利萨茹曲线:频率耦合的轨迹艺术
flutter·ui·数学建模·华为·harmonyos·鸿蒙系统
xmdy58661 天前
Flutter+开源鸿蒙实战|智安盾电商溯源平台Day3 溯源查询逻辑+鸿蒙网络请求适配
flutter·开源·harmonyos
maaath1 天前
【maaath】Flutter 跨平台日历日程应用开发实战
flutter·华为·harmonyos
LeesonWong1 天前
架构困境与四层结构化设计
harmonyos
梦想不只是梦与想1 天前
鸿蒙 应用市场更新功能:版本检测与更新提醒
harmonyos·鸿蒙·版本更新
xmdy58661 天前
Flutter+开源鸿蒙实战|智安盾电商溯源平台Day2 首页+核心入口UI开发(鸿蒙多端适配)
flutter·开源·harmonyos
jiejiejiejie_1 天前
Flutter for OpenHarmony 萌系 UI 实战合集:骨架屏 + 引导页一站式指南
flutter·ui·华为
nashane1 天前
HarmonyOS 6学习:HAR包与HSP包的选择与优化指南
学习·华为·harmonyos·harmonyos 5
全栈若城1 天前
自定义 TabBar 实战:浮动标签栏与舵式标签栏
harmonyos·harmonyos6·三方库开发