美文网首页
harmonyOS不同page间的slice的跳转及导航

harmonyOS不同page间的slice的跳转及导航

作者: harmonyOS小飞鱼 | 来源:发表于2020-12-21 12:48 被阅读0次

    一)page跳转到另一个page

    1)带参数,不带返回值

    在slice中

    intent1 =new Intent();

    intent1.setParam("data","page跳转到page");

    intent1.setAction("action.other.ability");//指定另一个page中的action的值

    startAbility(intent1);

    //===================================================================

    "action.other.ability"需要在另一个page中的onStar方法配置跳转路由:

     1)addActionRoute("action.other.ability",OtherAbilitySlice.class.getName());

    2)config.json需要配置

    "skills": [

    {

    "actions":

        [

            "action.other.ability"

        ]

    }

    ],

    2)page跳转到page,带返回值

      MaindAbility的MainAbilitySlice中中

       intent1 =new Intent();

        intent1.setAction("action.other.ability");

        intent1.setParam("data","page跳转到page-带返回值");

        startAbilityForResult(intent1,1001);

    /**

    * ability回调

    * @param requestCode

    * @param resultCode

    * @param resultData

    */

    @Override

    protected void onAbilityResult(int requestCode, int resultCode, Intent resultData)

    {

    super.onAbilityResult(requestCode, resultCode, resultData);

        if (requestCode ==1001)

    {

    String bundle = resultData.getStringParam("data");//获取回调后的内容

            HiLogUtils.HiLog("MainAbilitySlice:" +bundle);

            def_page_params.setText(bundle);

        }

    }

    //==========================================================

    另一SecondAbility中在onStart()中

    //配置跳转的路由的action

    addActionRoute("action.other.ability",OtherAbilitySlice.class.getName());

    @Override

    protected void onActive()

    {

       super.onActive();

        Intent intent =new Intent();

        intent.setParam("data","OtherAbility");

        setResult(1001,intent);

    }

    相关文章

      网友评论

          本文标题:harmonyOS不同page间的slice的跳转及导航

          本文链接:https://www.haomeiwen.com/subject/tvqfnktx.html