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