Intent同时传递传递类对象和其他数据


Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象。

要求被传递的对象必须实现上述2种接口中的一种才能通过Intent直接传递。

Intent中传递这2种对象的方法:

Bundle.putSerializable(Key,Object);  //实现Serializable接口的对象

Bundle.putParcelable(Key, Object); //实现Parcelable接口的对象

以下以最常用的Serializable方式为例 :

Intent 同时传递对象和其他类型的数据例子:

发送方:

Intent intent1 = new Intent(this,TuiHuoTuiKuanActivity.class);
Bundle bundle1 = new Bundle();
bundle1.putSerializable("shopinfo", shopinfo);
bundle1.putString("number", 1+"");
intent1.putExtras(bundle1);
startActivity(intent1);

接收方:

Intent intent = getIntent();
Bundle bundle = intent.getExtras();
shopinfo = (ShopInfo) bundle.getSerializable("shopinfo");
number = bundle.getString("number");


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值