Bundle(页面间的传值)

//传值
Intent i = new Intent(); Bundle bundle=new Bundle(); i.setClass(Reign.this, Login.class); bundle.putSerializable("data", (Serializable) user);//序列化user对象,data为标识,user必须实现
                     bundle.
putInt("yes",position);             //bundle可以同时传递多个值,用不同的标识
                                    //Serializable接口
                                    i.putExtras(bundle); //将值传递给下一个界面 startActivity(i);
//接收值
Intent it = getIntent(); if (it != null) { //先判断传过来的Intent是否为空 Bundle bundle = it.getExtras(); if (bundle != null) { //判断Bundle是否为null User user = (User) bundle.getSerializable("data"); if (user != null) { //判断传过来的user是否为null if (user.getId().equals(i) && user.getPwd().equals(p)) {
除了Bundle外,还可以用Intent直接传值,
it.putExtra("data","132");//data是标识,132是string类型的值,限制太多不常用

转载于:https://www.cnblogs.com/Xacm/p/5465915.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值