Harmony页面间的传值

本文介绍了Android应用程序中Intent的基本使用,包括普通传值和带有返回值的传值方式。通过示例展示了如何在Intent中设置参数并从Intent中获取值,以及如何利用`presentForResult`进行有返回值的传值和接收结果的操作。

普通传值

Intent intent1 = new Intent();
intent1.setParam("user", "gjw");
present(new DemoAbilitySlice(), intent1);

接收值

  public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_demo);
        if (intent != null) {
            Text Id_tv_intent = (Text) findComponentById(ResourceTable.Id_tv_intent);
            Id_tv_intent.setText("跳转界面传递获取的值:" + intent.getStringParam("user") + "");
        }
    }

带有返回值的传值

 Intent intent1 = new Intent();
intent1.setParam("user", "gjw");
 presentForResult(new DemoAbilitySlice(), intent1, 1000);

接收值

   @Override
    protected void onResult(int requestCode, Intent resultIntent) {
        super.onResult(requestCode, resultIntent);
        if (requestCode == 1000) {
            text3.setText("从上个界面返回,传递过来的值:" + 
            resultIntent.getStringParam("pw"));
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值