1. 基本数据类型

Intent intent = new Intent();
intent.setClass(activity1.this, activity2.class); //描述起点和目标
Bundle bundle = new Bundle(); //创建Bundle对象
bundle.putString("key", "包装的数据"); //装入数据
intent.putExtras(bundle); //把Bundle塞入Intent里面
startActivity(intent);

2. 传对象的两种方式 java.io.Serializable和android.os.Parcelable
1. android.os.Parcelable(android推荐使用)
1).被传递的类对象需要实现parcelable接口

public class Employee implements Parcelable{
public String id;
public String name;
public String dept;
public String idcard;
public String statusInt;
public String status;
public String mobile;
public String sex;
public String sexInt;
public String address;
public String avatar;
public String education;
public String birthday;
public String age;
public String dept_name;
public String imageUrl;
public String manager;
public String score; public static final Parcelable.Creator<Employee> CREATOR = new Creator<Employee>() {
public Employee createFromParcel(Parcel source) {
Employee employee = new Employee();
employee.name = source.readString();
employee.age = source.readString();
employee.dept_name = source.readString();
employee.sex = source.readString();
employee.status = source.readString();
employee.manager = source.readString();
employee.score = source.readString();
employee.imageUrl = source.readString();
return employee;
}
public Employee[] newArray(int size) {
return new Employee[size];
}
}; @Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int arg1) {
parcel.writeString(name);
parcel.writeString(age);
parcel.writeString(dept_name);
parcel.writeString(sex);
parcel.writeString(status);
parcel.writeString(manager);
parcel.writeString(score);
parcel.writeString(imageUrl);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
} }

2)传递对象代码

Intent intent = new Intent(mContext, AnotherActivity.class);
Bundle mEmployeeBundle = new Bundle();
mEmployeeBundle.putParcelable(EMPLOYEE_PAR_KEY, mEmployees.get(position));
intent.putExtras(mEmployeeBundle);
startActivity(intent);

3) AnotherActivity中取值

mEmployee = (Employee)getIntent().getExtras().getParcelable(HomeFragment.EMPLOYEE_PAR_KEY);
Log.d(TAG, "employee name :"+mEmployee.name);

2. java.io.Serializable

1)类对象

public class Ser implements Serializable {

    /**
* serialVersionUID的作用是在修改实体类后,可以正常的序列化和反序列化,在此不多说,大家可以谷歌百度下。
*/
private static final long serialVersionUID = 123456789090L;
private String name;
private int age;
}

2)传值及取值

bundle.putSerializable(SER_KEY, new Ser());
intent.putExtras(bundle);
startActivity(intent);
pSer = (Ser) getIntent().getSerializableExtra(SER_KEY); //another activity 取值 

android intent 传数据的更多相关文章

  1. android中用Intent传数据,如果用传递的是一个类,就将类实现Parcelable接口

    Parcelable,内存单位,跨进程使用,或者intent传递对象的时候使用.android中用Intent传数据,如果用传递的是一个对象,就将对象实现Parcelable接口,而不是将对象序列化. ...

  2. 关于 android Intent 传对象和对象数组的一些操作

    直接开正题,Intent传递值就是平常那些很简单的,接下来介绍传递 对象,和 对象数组 1 .intent 传递自定义的 对象 - 实体类继承  Serializable public class A ...

  3. Android Intent传递数据

    刚开始看郭大神的<>,实现以下里面的一些例子.Intent传递数据. 我们利用显示的方式进行Intent的启动. 1.启动intent并输入数据. Intent intent=new In ...

  4. Intent 传数据

    Intent作为android重要的组件其重要性不言而喻,这里说说他是怎么传递简单数据和对象 Intent的具体概念就不讲解了!网上有很多的 传递简单的数据(例如String,float等) 传递对象 ...

  5. Android Intent 传递数据注意事项

    不要通过 Intent 在 Android 基础组件之间传递大数据(binder transaction缓存为 1MB),可能导致 OOM.

  6. Android:Intent传递数据的几种类型和源码实现

    public class Intent implements Parcelable, Cloneable {   //... private String mAction; private Uri m ...

  7. 【转】Android 之最新最全的Intent传递数据方法

    原文地址:https://www.jianshu.com/p/1169dba99261 intent传递数据 为什么要和intent单独拿出来讲,因为Intent传递数据也是非常重要的 一.简单的传递 ...

  8. Android开发探秘之四:利用Intent实现数据传递

    在Android开发过程中,很多人都熟悉Intent,这是个用于在多个View之间共享数据的类.本节主要是继承上节,通过点选ListView中的文本,把文本中的URL加载到一个新的页面上,并且打印出来 ...

  9. Android 消息广播Intent传递数据

    1.创建布局文件activity_broadcast.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk ...

随机推荐

  1. C++STL简介

    本文仅仅是个人学习的过程中结合网上博文,对STL的整理,也仅仅是简介.仅为个人学习笔记. 一.STL简介(摘自:晨光(Morning)) STL(Standard Template Library), ...

  2. LeetCode中二叉树题目总结

    本文仅为博主个人总结,水平有限,欢迎大神指出不妥处. 关于二叉树的相关概念可以参见二叉树的百度百科,或binary tree Wiki. 二叉树结点类的常见定义为: /* Definition for ...

  3. js空对象判断 isPlainObject

    //有缺陷,JSON.stringify(obj)中,如果obj本来是空的,又继承了一个非空的对象那么结果也会是“{}” 1. JSON.stringify(obj) == '{}' 2. Objec ...

  4. 使用openssl实现RSA非对称加密

    生成公钥私钥 使用命令生成私钥 openssl genrsa - 参数:genrsa 生成密钥   -out 输出到文件  rsa_private_key.pem 文件名  1024 长度 从私钥中提 ...

  5. Codeforces Round #394 (Div. 2)A水 B暴力 C暴力 D二分 E dfs

    A. Dasha and Stairs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #401 (Div. 2) A B C 水 贪心 dp

    A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...

  7. 分别利用并查集,DFS和BFS方法求联通块的数量

    联通块是指给定n个点,输入a,b(1<=a,b<=n),然后将a,b连接,凡是连接在一起的所有数就是一个联通块: 题意:第一行输入n,m,分别表示有n个数,有输入m对连接点,以下将要输入m ...

  8. C语言超大数据相加计算整理

    在做ACM 1002题时,整理得到. #include<stdio.h>#include<string.h>#define MAX 1000void zero(char *s, ...

  9. 爬虫服务集群处理nginx返回504

    最近在对爬虫服务做分布式服务的时候总是遇到服务器返回504,搞了两天才发现原来是nginx中有对超时的设置参数,自己都是用默认的,然而客户端的等待时间超过了nginx默认的超时设置 修改 keepal ...

  10. 2017 济南综合班 Day 6

    循环移动 (cyclic.cpp/c/pas) (1s/256M) 问题描述 给出一个字符串S与N个操作.每个操作用三元组(L, R, K)进行描述:操作将字符串第L个到第R个位置构成的子串循环移动K ...