Android中Bundle的用法

要求 将 Activity A中的数据传到C;
跳转为  Activity  A-B-C
利用 Bundle 进行数据传值 节省代码
//A类 进行跳转时 相关的代码
Bundle bundle = new Bundle();
bundle.putString("key_1","1111111111111111111111");
bundle.putString("key_2","222222222222222222222");
bundle.putString("key_3","333333333333333333333");
bundle.putString("key_4","444444444444444444444");
Intent intent = new Intent(A.this, B.class);
intent.putExtra("bundle",bundle);
startActivity(intent);
//B类  
Intent i = getIntent();
Bundle bundle = i.getBundleExtra("bundle")
bundle.putString("key_5","555555555555555555555555555");
//B类 进行跳转时 相关的代码
Intent intent = new Intent(B.this, C.class);
intent.putExtra("bundle",i.getBundleExtra("bundle"));
startActivity(intent);

//C类 接受数据
Intent i = getIntent();
Bundle bundle = i.getBundleExtra("bundle");
//根据Key 得到对应的值
String key_1=getString("key_1");
String key_2=getString("key_2");
String key_3=getString("key_3");
String key_4=getString("key_4");
String key_5=getString("key_5");

//=============================================================
个人认为
Bundle 与 Intent 本质是一样的;
Bundle 具有封装性可以节省代码



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值