zoukankan      html  css  js  c++  java
  • 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类型的值,限制太多不常用
  • 相关阅读:
    hbase 自定义过滤器
    idea的protobuf使用
    Docker自动补全容器名
    Docker普通用户不使用sudo提权
    Hadoop安装错误总结
    Git中撤销提交
    Python经典算法片段
    Git设置彩色输出
    Git同步远程fork的项目
    Git错误汇总
  • 原文地址:https://www.cnblogs.com/Xacm/p/5465915.html
Copyright © 2011-2022 走看看