intent传对象
intent还有一个很好用的地方,就是传输对象,但要注意的是这里的传输只是将对象复制了一份通过intent进行传递,并不能达到实时更新的效果,也就是这个对象等偏重于“读”。intent对这个对象有着严格的要求----Parcel。
package com.yingjie.jzlfapp.model.local; import android.os.Parcel;
import android.os.Parcelable; /**
* 类名称: Dede_MemberAnswer 功能描述:回答的视图 作者: chrizz00 创建日期: 2014-1-23 下午2:04:50
*/
public class PersonCenterAnswer implements Parcelable { private Integer tid;
// 回答问题类型
private String tidname; // 回答者id
private Integer replierid;
// 回答者
private String replier; //问题的id
private Integer questionid;
//问题
private String title; //提问者的id
private Integer askerid;
//提问者
private String asker; //提问的时间
private long asktime;
//回答的时间
private long answertime;
//解决的时间
private long solvetime; // 被采纳的回答的id
private Integer bestanswer; //回答的id
private Integer answerid;
//回答的内容
private String content; public PersonCenterAnswer() { } public PersonCenterAnswer(Integer tid, String tidname, Integer replierid,
String replier, Integer questionid, String title, Integer askerid,
String asker, long asktime, long answertime, long solvetime,
Integer bestanswer, Integer answerid, String content) {
super();
this.tid = tid;
this.tidname = tidname;
this.replierid = replierid;
this.replier = replier;
this.questionid = questionid;
this.title = title;
this.askerid = askerid;
this.asker = asker;
this.asktime = asktime;
this.answertime = answertime;
this.solvetime = solvetime;
this.bestanswer = bestanswer;
this.answerid = answerid;
this.content = content;
} public Integer getTid() {
return tid;
} public void setTid(Integer tid) {
this.tid = tid;
} public String getTidname() {
return tidname;
} public void setTidname(String tidname) {
this.tidname = tidname;
} public Integer getReplierid() {
return replierid;
} public void setReplierid(Integer replierid) {
this.replierid = replierid;
} public String getReplier() {
return replier;
} public void setReplier(String replier) {
this.replier = replier;
} public Integer getQuestionid() {
return questionid;
} public void setQuestionid(Integer questionid) {
this.questionid = questionid;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public Integer getAskerid() {
return askerid;
} public void setAskerid(Integer askerid) {
this.askerid = askerid;
} public String getAsker() {
return asker;
} public void setAsker(String asker) {
this.asker = asker;
} public long getAsktime() {
return asktime;
} public void setAsktime(long asktime) {
this.asktime = asktime;
} public long getAnswertime() {
return answertime;
} public void setAnswertime(long answertime) {
this.answertime = answertime;
} public long getSolvetime() {
return solvetime;
} public void setSolvetime(long solvetime) {
this.solvetime = solvetime;
} public Integer getBestanswer() {
return bestanswer;
} public void setBestanswer(Integer bestanswer) {
this.bestanswer = bestanswer;
} public Integer getAnswerid() {
return answerid;
} public void setAnswerid(Integer answerid) {
this.answerid = answerid;
} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
} public PersonCenterAnswer(Parcel source) {
185
186 this.tid = source.readInt();
187 this.tidname = source.readString();
188 this.replierid = source.readInt();
189 this.replier = source.readString();
190 this.questionid =source.readInt();
191 this.title = source.readString();
192 this.askerid = source.readInt();
193 this.asker = source.readString();
194 this.asktime = source.readLong();
195 this.answertime = source.readLong();
196 this.solvetime = source.readLong();
197 this.bestanswer = source.readInt();
198 this.answerid =source.readInt();
199 this.content = source.readString();
200 } @Override
public int describeContents() {
return 0;
} @Override
209 public void writeToParcel(Parcel dest, int flags) {
210 dest.writeInt(tid);
211 dest.writeString(tidname);
212 dest.writeInt(replierid);
213 dest.writeString(replier);
214 dest.writeInt(questionid);
215 dest.writeString(title);
216 dest.writeInt(askerid);
217 dest.writeString(asker);
218 dest.writeLong(asktime);
219 dest.writeLong(answertime);
220 dest.writeLong(solvetime);
221 dest.writeInt(bestanswer);
222 dest.writeInt(answerid);
223 dest.writeString(content);
224 } public static final Parcelable.Creator<PersonCenterAnswer> CREATOR = new Parcelable.Creator<PersonCenterAnswer>(){ @Override
public PersonCenterAnswer createFromParcel(Parcel source) { return new PersonCenterAnswer(source);
} @Override
public PersonCenterAnswer[] newArray(int size) { return new PersonCenterAnswer[size];
} }; @Override
public String toString() {
return "PersonCenterAnswer [tid=" + tid + ", tidname=" + tidname
+ ", replierid=" + replierid + ", replier=" + replier
+ ", questionid=" + questionid + ", title=" + title
+ ", askerid=" + askerid + ", asker=" + asker + ", asktime="
+ asktime + ", answertime=" + answertime + ", solvetime="
+ solvetime + ", bestanswer=" + bestanswer + ", answerid="
+ answerid + ", content=" + content + "]";
} }
writeToParcel (Parcel dest, int flags) 和PersonCenterAnswer(Parcel source)方法体里面的write和read的顺序要一一对应,不能出错!!切记!!
传输的时候直接intent.putExtra("answers", answerss); (answers=PersonCenterAnswer)
在接收端直接 PersonCenterAnswer person =(PersonCenterAnswer) getIntent().getParcelableExtra("answers");
再次注意:这个person只是一个复制品,并不是传输前的那个对象。
如果需要同步,可以考虑将这个对象回传回去,在替换成先前的那个对象,试过可行,稍麻烦。
intent传对象的更多相关文章
- 关于 android Intent 传对象和对象数组的一些操作
直接开正题,Intent传递值就是平常那些很简单的,接下来介绍传递 对象,和 对象数组 1 .intent 传递自定义的 对象 - 实体类继承 Serializable public class A ...
- intent传值传对象跳转
intent传值传对象跳转 1.传值 //原activity中存入一个字段 intent = new Intent(From.this, To.class); intent.putExtra(&quo ...
- Intent 传数据
Intent作为android重要的组件其重要性不言而喻,这里说说他是怎么传递简单数据和对象 Intent的具体概念就不讲解了!网上有很多的 传递简单的数据(例如String,float等) 传递对象 ...
- android intent 传数据
1. 基本数据类型 Intent intent = new Intent(); intent.setClass(activity1.this, activity2.class); //描述起点和目标 ...
- android中用Intent传数据,如果用传递的是一个类,就将类实现Parcelable接口
Parcelable,内存单位,跨进程使用,或者intent传递对象的时候使用.android中用Intent传数据,如果用传递的是一个对象,就将对象实现Parcelable接口,而不是将对象序列化. ...
- Intent传递对象的几种方式
原创文章.转载请注明 http://blog.csdn.net/leejizhou/article/details/51105060 李济洲的博客 Intent的使用方法相信你已经比較熟悉了,Inte ...
- Android 全局获取 Context 与使用 Intent 传递对象
=====================全局获取 Context======================== Android 开发中很多地方需要用到 Context,比如弹出 Toast.启动活 ...
- Android开发——使用intent传递对象
intent传递对象有两种方法: 方式一:Serializable 方式 方式二:Parcelable方式 在这里不多介绍了,这一篇就是快速上手使用教程,至于详细原理介绍的,请看这一篇http://w ...
- onclick传对象
用onclick传对象的时候,用jquery无法进行操作 onclick=(this) 接收到参数后只需要转化一下 console.log($(obj).html());
随机推荐
- 2013ACM-ICPC亚洲区南京站现场赛G题
题目大意:一个n维的系统中随机选一个向量(X1,X2,X3,...,Xn),其中0<=Xi<=R,且X1^2+X2^2+X3^2+……+Xn^2 <= R^2. 现在给定n,R.求X ...
- Uber License for Android
Uber license for android list: 1.Butter Knife: 项目地址:https://github.com/JakeWharton/butterknife 这个开源库 ...
- SQL Server 数据库游标选项
背景: 游标控制服务器端游标的行为,相关的T-SQL如下: declare , open , fetch , close , deallocate. 1. cursor_close_on_commit ...
- JDK常见问题 环境变量配置
"javac不是内部命令或外部命令" Windows7 安装"jdk-6u26-windows-x64.exe"后,常提示"javac不是内部命令或外 ...
- Delphi 服务操作
unit Service; interface uses Windows,Messages,SysUtils,Winsvc,Dialogs; function StartServices(Const ...
- rsyslog 日志服务器端配置
$EscapeControlCharactersOnReceive off #关闭rsyslog默认转译ASCII<32的所有怪异字符,包括换行符等 $template tocFormat,&q ...
- 全国计算机等级考试二级教程-C语言程序设计_第13章_编译预处理和动态存储分配
free(p);//释放内存 p = NULL;//软件工程规范,释放内存以后,指针应该赋值为空 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h ...
- vmware虚拟机迁移导致的eth0消失问题
将原来的ubuntu虚拟机文件迁移到还有一台机子之后. ifconfig显示仅仅有一个lo网卡,网上找了一些文章.大多是改动/etc/network/interfaces 原来内容是 # ###### ...
- IOS学习笔记06---C语言函数
IOS学习笔记06---C语言函数 -------------------------------------------- qq交流群:创梦技术交流群:251572072 ...
- SQL整理4
--====================简单增删改===========--查看学生表的全部数据select * from studio --插入一个新的学生信息insert into stu ...