zoukankan      html  css  js  c++  java
  • HarmonyOS Activity页面跳转

    1.同一activity间slice跳转

    2.跳转不同activity

    一 同一activity间slice跳转

    日志类:声明+调用

    public static final HiLogLabel hiLogLabel = new HiLogLabel(HiLog.LOG_APP, 0x00201, "ligy");
     HiLog.info(hiLogLabel,"onClick 方法");

    1.跳转到第二个slice

     Button btn = (Button) findComponentById(ResourceTable.Id_btnNext);
    
            //跳转slice
            btn.setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component component) {
                    present(new NextSlice(),new Intent());
                    HiLog.info(hiLogLabel,"onClick 方法");
                }
            });

    2.传值+回传

    //跳转slice:传值+回传
            btn.setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component component) {
                    Intent param = new Intent();
                    param.setParam("id", "1");
                    param.setParam("name", "jack1");
                    presentForResult(new NextSlice(), param, 100);
                }
            });
     @Override
        protected void onResult(int requestCode, Intent resultIntent) {
            super.onResult(requestCode, resultIntent);
    
            if (requestCode == 100) {
                if (resultIntent != null) {
                    String msg = resultIntent.getStringParam("msg");
                    HiLog.info(hiLogLabel, "回传值:" + msg);
                }
            }
        }
    public void onStart(Intent intent) {
            super.onStart(intent);
            super.setUIContent(ResourceTable.Layout_next);
    
            if(intent != null){
                HiLog.info(hiLogLabel, intent.getStringParam("id"));
                HiLog.info(hiLogLabel, intent.getStringParam("name"));
            }
    
            Button btn = (Button)findComponentById(ResourceTable.Id_btnUp);
            btn.setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component component) {
                    Intent t = new Intent();
                    t.setParam("msg","这是next返回的值");
    
                    //present(new MainAbilitySlice(),t);
                    setResult(t);
                    terminate();
                }
            });
        }

    二 跳转不同activity

    1.跳转到第二个activity

    //跳转Ability
            btn.setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component component) {
                    Intent intent1 = new Intent();
                    Operation operation = new Intent.OperationBuilder()
                            .withDeviceId("")
                            .withBundleName("com.example.myapplication3")
                            .withAbilityName("com.example.myapplication3.TestAbility")
                            .build();
                    intent1.setOperation(operation);
    
                    startAbility(intent1);
                }
            });

    2.传值+回传

    同上

    天生我材必有用,千金散尽还复来
  • 相关阅读:
    n8n 基于node 的流程自动化工具
    kubectl-trace 基于bpftrace 的kubernetes 集群性能分析工具
    bcc 基于bpf 分析linux 系统性能的强大工具包
    使用arthas 生成火焰图分析jvm
    openjdk11 stretch基础镜像无法找到对应openjdk dbg 包的问题
    async-profiler 容器使用常见问题
    使用jattach 在host 节点查看容器jvm信息
    使用async-profiler简单分析zeebe 工作流引擎的性能
    minio select api 试用
    使用zeebe DebugHttpExporter 查看zeebe 工作流信息
  • 原文地址:https://www.cnblogs.com/ligenyun/p/15552025.html
Copyright © 2011-2022 走看看