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());
随机推荐
- mysql的约束的讨论
问题:该不该加约束,比如非空约束,外键约束 学院派会告诉你在设计的时候把应该有的约束都加上 而实践派得出的结论是主键一定加,非空约束尽量加,外键最好依赖于程序逻辑,而不是数据库,从而更好的拥抱变化,快 ...
- mysql的高级用法
1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql server --- 创建 备份 ...
- JS中定义类的方法<转>
转载地址:http://blog.csdn.net/sdlfx/article/details/1842218 PS(个人理解): 1) 类通过prototype定义的成员(方法或属性),是每个类对象 ...
- Binder的使用(跨进程——AIDL,非跨进程)
一.Binder类 1.作用:Binder是客户端与服务器端的通信的媒介(连接各种Manager的桥梁),客户端通过Binder对象获取服务器端提供的数据 (为什么要用Binder来提供数据呢,服务器 ...
- php 查找数组中是否存在某项,并返回指定的字符串,可用于检查复选,单选等
/** * 查找数组中是否存在某项,并返回指定的字符串,可用于检查复选,单选等 * @param $id * @param $ids * @param string $returnstr * @ret ...
- 为程序指定运行时所在的CPU核
internal class Program { [DllImport("kernel32.dll")] private static extern uint GetTickCou ...
- 论山寨手机与Android联姻 【8】 自己动手做XP手机
2010年1月20日,ViewSonic在北京发布了一款真正意义的电脑手机VCP08.根据商家的宣传,VCP08之所以能够被称为真正的电脑手机,是因为“该机做到了把真正的WindowsXP操作系统嵌入 ...
- docker 指定容器名字
docker:/root# docker run -itd --name linux123 ubuntu /bin/bash Unable to find image 'ubuntu:latest' ...
- KO.js学习笔记(一)
1.官方网站:knockoutjs.com 2.要dom树加载完毕才能绑定数据 3.ui能实时更新,使用了ko的一个自定义属性:data-bind 4.可以对viewmodel中的属性添加subsci ...
- centos 6.5安装GitLab全过程和问题记录
GitLab,是一个使用 Ruby on Rails 开发的开源应用程序,与Github类似,能够浏览源代码,管理缺陷和注释,非常适合在团队内部使用. 官方只提供了Debian/Ubuntu系统下的安 ...