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.传值+回传

    同上

    天生我材必有用,千金散尽还复来
  • 相关阅读:
    观光奶牛Sightseeing Cows (二分+spfa(dfs))
    卢卡斯定理学习笔记
    分层图学习笔记
    热烈祝贺CRMEB运营中心乔迁新址
    CRMEB知识付费系统v1.2发布上线直播带课功能
    推荐一款超好用码云start超4.9k采用前后端分离开发的小程序商城源码
    crmeb打通版3.x小程序商城公众号重复无限刷新登陆解决
    如何利用CRMEB 3.2打通版小程序商城做直播带货
    crmeb打通版开源微信公众号小程序商城框架源码
    一文读懂知识付费平台的运营方向及平台选择
  • 原文地址:https://www.cnblogs.com/ligenyun/p/15552025.html
Copyright © 2011-2022 走看看