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

相关推荐
小雨下雨的雨4 小时前
Flutter 框架跨平台鸿蒙开发 —— SingleChildScrollView 控件之长内容滚动艺术
flutter·ui·华为·harmonyos·鸿蒙
2501_944521005 小时前
rn_for_openharmony商城项目app实战-商品评价实现
javascript·数据库·react native·react.js·ecmascript·harmonyos
lili-felicity5 小时前
React Native for Harmony 企业级 Grid 宫格组件 完整实现
react native·react.js·harmonyos
以太浮标6 小时前
华为eNSP模拟器综合实验之- VLAN聚合(VLAN Aggregation或Super VLAN)解析
运维·网络·华为·信息与通信
lili-felicity7 小时前
React Native 鸿蒙跨平台开发:动态表单全场景实现
react native·harmonyos
奋斗的小青年!!7 小时前
Flutter跨平台开发适配OpenHarmony:文件系统操作深度实践
flutter·harmonyos·鸿蒙
SunkingYang8 小时前
从硬件参数、系统等方面详细对比华为mate80 pro max与iPhone17 pro max
华为·苹果·iphone17·mate80·promax·手机对比
奋斗的小青年!!9 小时前
Flutter跨平台开发OpenHarmony应用:个人中心实现
开发语言·前端·flutter·harmonyos·鸿蒙
人工智能知识库9 小时前
2026年HCCDP-GaussDB工作级开发者题库(详细解析)
数据库·华为·gaussdb·题库·hccdp-gaussdb·工作级开发者认证
IT=>小脑虎10 小时前
鸿蒙开发零基础小白学习知识点【基础版·详细版】
学习·华为·harmonyos