Intent使用Parcelable传递对象
package com.pingyijinren.test; import android.os.Parcel;
import android.os.Parcelable; import java.io.Serializable; /**
* Created by Administrator on 2016/5/20 0020.
*/
public class Person implements Parcelable{
private String name;
private int age; @Override
public int describeContents(){
return 0;
} @Override
public void writeToParcel(Parcel dest, int flags){
dest.writeString(name);
dest.writeInt(age);
} public static final Parcelable.Creator<Person> CREATOR=new Parcelable.Creator<Person>(){
@Override
public Person createFromParcel(Parcel source){
Person person=new Person();
person.name=source.readString();
person.age=source.readInt();
return person;
} @Override
public Person[] newArray(int size){
return new Person[size];
}
}; public void setName(String name){
this.name=name;
} public void setAge(int age){
this.age=age;
} public String getName(){
return name;
} public int getAge(){
return age;
}
}
package com.pingyijinren.test; import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; public class IndexActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_index); Intent intent=new Intent(this,TransferObjectActivity.class);
Person person=new Person();
person.setAge(26);
person.setName("张钦雄");
intent.putExtra("person",person);
startActivity(intent);
}
}
package com.pingyijinren.test; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log; public class TransferObjectActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transfer_object); Person person=getIntent().getParcelableExtra("person");
Log.d("MainActivity",person.getName()+" "+person.getAge());
}
}
Intent使用Parcelable传递对象的更多相关文章
- 在Android中通过Intent使用Bundle传递对象
IntentBundle传递对象SerializableParcelable Android开发中有时需要在应用中或进程间传递对象,下面详细介绍Intent使用Bundle传递对象的方法.被传递的对象 ...
- Intent之对象传递(Parcelable传递对象和对象集合)
接着上一篇文章,以下我们讨论一下怎样利用Parcelable实现Intent之间对象的传递 一.实现对象传递 首先创建User.java实现Parcelable接口: package org.yayu ...
- intent使用Serializable传递对象
package com.pingyijinren.test; import android.content.Intent; import android.support.v7.app.AppCompa ...
- Intent传递对象的两种方法(Serializable,Parcelable) (转)
今天讲一下Android中Intent中如何传递对象,就我目前所知道的有两种方法,一种是Bundle.putSerializable(Key,Object);另一种是Bundle.putParcela ...
- Android中Intent传递对象的两种方法(Serializable,Parcelable)
今天要给大家讲一下Android中 Intent中如何传递对象,就我目前所知道的有两种方法,一种是Bundle.putSerializable(Key,Object);另一种是 Bundle.putP ...
- [转]Android中Intent传递对象的两种方法(Serializable,Parcelable)
http://blog.csdn.net/xyz_lmn/article/details/5908355 今天要给大家讲一下Android中Intent中如何传递对象,就我目前所知道的有两种方法,一种 ...
- Android高手进阶教程(十七)之---Android中Intent传递对象的两种方法(Serializable,Parcelable)!
[转][原文] 大家好,好久不见,今天要给大家讲一下Android中Intent中如何传递对象,就我目前所知道的有两种方法,一种是Bundle.putSerializable(Key,Object); ...
- Android中如何使用Intent在Activity之间传递对象[使用Serializable或者Parcelable]
http://blog.csdn.net/cjjky/article/details/6441104 在Android中的不同Activity之间传递对象,我们可以考虑采用Bundle.putSeri ...
- Intent传递对象——Serializable和Parcelable区别
为什么要将对象序列化? 1.永久性保存对象,保存对象的字节序列到本地文件中: 2.用过序列化对象在网络中传递对象: 3.通过序列化对象在进程间传递对象. 1.实现Serializable接口 Seri ...
随机推荐
- String的用法——判断功能
package cn.itcast_03; /* String的判断功能: 1.boolean equals(Object obj):字符串的内容是否相同,区分大小写 2.boolean equals ...
- dotnet cors 跨域问题
研究了一整子的.net core框架,感觉挺好用的,可以用在实际项目中,前端avalon框架也在研究: 问题:跨域,相比原来的跨域解决方案,还是有不小的变化的,原来的.net api 只需要在WebA ...
- XCode的debug断点调试
debug 流程控制 当你通过 Xcode 的源码编辑器的侧边槽 (或者通过下面的方法) 插入一个断点,程序到达断点时会就会停止运行. 调试条上会出现四个你可以用来控制程序的执行流程的按钮. 从左到右 ...
- JavaScript——blob、file、flieReader、createObjectURL
https://blog.csdn.net/opengl_es/article/details/44336477 https://www.cnblogs.com/hhhyaaon/p/5928152. ...
- 【译】x86程序员手册38-10.2实在址模式下的软件初始化
10.2 Software Initialization for Real-Address Mode 实地址模式的软件初始化 In real-address mode a few structur ...
- VS2015 update3 安装 asp.net core 失败
CMD 命令下执行: C:\DotNetCore\DotNetCore.1.0.0-VS2015Tools.Preview2.exe SKIP_VSU_CHECK=1
- swift 即使不使用oc的动态派发机制也应该借鉴isa类型识别机制
目前的消息派发机制真的很鸡肋. 简直是一堆狗屎. 类型信息中包含所有需要动态派发的函数:这个包含两类:类和protocol: 在编译时,首先搜索动态派发列表: 动态派发列表没有,在搜索静态派发列表: ...
- QList模板类常用接口函数
插入操作:insert()函数原型:void QList::insert(int i, const T &value) 在索引后插入值 i:索引 value:插入值 Example: QLis ...
- fedora27安装ssh
Fedora安装sshd 先确认是否已安装ssh服务: [root@localhost ~]# rpm -qa | grep openssh-server openssh-server-5.3p1-1 ...
- css3 平行四边形 、大括弧
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...