类实现了Parcelable接口就可以在Intent中传递   只要在类的定义中实现Parcelable接口

代码

 package entity;

 import android.os.Parcel;
import android.os.Parcelable; public class Person implements Parcelable { private int id;
private String name;
private String pass; public Person() {
super();
// TODO Auto-generated constructor stub
} public Person(int id, String name, String pass) {
super();
this.id = id;
this.name = name;
this.pass = pass;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPass() {
return pass;
} public void setPass(String pass) {
this.pass = pass;
} @Override
public String toString() {
return "Person [id=" + id + ", name=" + name + ", pass=" + pass + "]";
}
//----------实现内容描述
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
//-------------写入到包中 注意 写入顺序
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeInt(id);
dest.writeString(name);
dest.writeString(pass); }
// 添加一个静态成员,名为CREATOR,该对象实现了Parcelable.Creator接口
public static final Parcelable.Creator<Person> CREATOR = new Creator<Person>() { @Override
public Person[] newArray(int size) {
// TODO Auto-generated method stub
return new Person[size];
} @Override
public Person createFromParcel(Parcel source) {
// 从Parcel中读取数据,返回person对象 --------------按顺序读
return new Person(source.readInt(), source.readString(),
source.readString());
}
}; }

Person

类实现Parcelable接口在Intent中传递的更多相关文章

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

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

  2. Android 在Intent中传递接口

    总结:在Activity中不能用intent传递匿名接口,原因如下:Activity A中生成了匿名接口M, 这个接口的引用就在组Activity A中,Activity A会禁止接口M 序列化.因为 ...

  3. 错误 1 类,结构或接口成员声明中的标记"="无效

    using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace Console ...

  4. 第二章——Parcelable接口的使用(跨进程,Intent传输)

    一.Parcelable类(Android独有的) 简介:Parcelable是一个接口. 作用:是Android提供的序列化接口,实现序列化和反序列化的操作. 二.跨进程使用 步骤一:创建Book类 ...

  5. Intent.putExtra()传递Object对象或者ArrayList<Object> (转)

    Intent传递基本类型相信大家都十分熟悉,如何传递Object对象或者ArrayList<Object>对象呢? 可以通过: (1)public Intent putExtra (Str ...

  6. intent--Activity之间数据传递之Intent数据传递

    intent传值: 4,intent传集合 3,intent传对象, 2,传递后有返回值的情况:当需要从目标Activity回传数据到原Activity时,可以使用上述方法定义一个新的Intent来传 ...

  7. 实体类实现Parcelable(包含boolean类型)

    实体类实现Parcelable接口需要实现方法: public ExtSignClockEntity(Parcel in) { timeMess = in.readString(); repeatMe ...

  8. Intent传递实现Parcelable接口的对象

    Intent可以传递基本数据类型,在对象实现了Parcelable接口后,Intent也可以传递对象. 1. 使类ListVideo实现了Parcelable接口. package com.examp ...

  9. Android中Parcelable接口的使用

    在做开发的过程中,序列化是非常常见的.比如要将对象保存本地磁盘或者在网络上传输等.实现序列化有两种方式,一种是实现Serializable接口,第二种是实现Parcelable. Serializab ...

随机推荐

  1. git 上传本地代码到github 服务器

    git init git add . (所有文件用 点表示) git commit -m "注释语句" git remote add origin https://github.c ...

  2. OTL技术应用

    什么是OTL:OTL 是 Oracle, Odbc and DB2-CLI TemplateLibrary 的缩写,是一个操控关系数据库的C++模板库,它目前几乎支持所有的当前各种主流数据库,如下表所 ...

  3. SQL FORMAT() 函数实例

    FORMAT()函数用于对字段的显示进行格式化. SQL FORMAT() 语法 SELECT FORMAT(column_name,format) FROM table_name; 参数 描述 co ...

  4. 【RL前沿】深度强化学习的最新进展 by 2017.12.12

    作者:Volodymyr Mnih Google DeepMind科学家. 在Geoffrey Hinton的指导下完成了多伦多大学的机器学习博士学位. 在此之前,在Csab Szepesvari的指 ...

  5. python之路day03

    1  复习计算机基础 计算机基础我们讲到完整的计算机系统包括了:应用程序,操作系统,硬件三部分.那么硬件又分为:cpu,内,和硬盘. 对于用户来说我们操作计算机是通过应用程序来间接控制计算机.当我们打 ...

  6. Selenium如何定位动态id的元素?

    怎么定位这类型的元素呢? 根据其他属性定位如果有其他固定属性,最先考虑的当然是根据元素的其他属性来定位,定位方式那么多,何必在这一棵树上吊死.. 根据相对关系定位根据其附近的父节点.子节点.兄弟节点定 ...

  7. 【C语言】09条件编译

    条件编译的概念;通常我们希望程序的其中一部分代码只有在满足一定的情况下才进行编译,否则不参与编译,(只有参与编译的代码最终才能被执行) 这就是条件编译; 基本用法; #if condication01 ...

  8. python入门-存储数据

    这里的存储数据使用json格式 json   是javascript object notation的意思  javascript的对象标记 1 写入 json.dump import json nu ...

  9. c#面向对象基础4

    一.namespace 命名空间 作用:解决不同类重名的问题  我们可以认为类是属于命名空间的 当我们需要再一个类中与另一个类建立关系时,通过命名空间来区别不同的类.所以需要我们这样做:导入命名空间 ...

  10. ListView 操作

    TListItem *Item; ; i < ; i++) { Item = ListView1->Items->Add(); Item->Caption = i; } Lis ...