Android开发:不同的Activity之间…

本文介绍Android应用中不同Activity间如何使用Bundle对象进行数据传递。具体步骤包括在发送Activity中创建Intent并设置目标Activity,然后通过putExtra方法将包含数据的Bundle附加到Intent上;在接收Activity中,通过getIntent().getExtras()获取传入的数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 Android的不同的Activity之间的数据传递,类似于桌面软件开发中不同窗体间的数据传递。

android通过bundle对象来传递数据

Activity1:

  文件名:Form1.java

       
        Intent intent = new Intent();
        intent.setClass(Form1.this, Form2.class);
       
        Bundle bundle = new Bundle();
        bundle.putDouble("param1", 176);
        bundle.putString("param2", 'hello');
       
        intent.putExtras(bundle);
       
        startActivity(intent);

Activity2:

  文件名:Form2.java

       
        Bundle bundle = this.getIntent().getExtras();

       
        String sex = bundle.getString("param1");
        double height = bundle.getDouble("param2");

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值