android传递对象有两种方式:

一种是Serializable和Parcelable

对于第一种方式:

import java.io.Serializable;





public class ShopData implements Serializable {

public String shopId;

public String name;

public String url;

public String info;





public String getShopId() {

return shopId;

}





public void setShopId(String shopId) {

this.shopId = shopId;

}





public String getName() {

return name;

}





public void setName(String name) {

this.name = name;

}





public String getUrl() {

return url;

}





public void setUrl(String url) {

this.url = url;

}





public String getInfo() {

return info;

}





public void setInfo(String info) {

this.info = info;

}





}

传递值的时候这样来传递:

	<span style="white-space:pre">			</span>Intent intent = new Intent();
ShopData shopData = (ShopData)mAdapter.getItem(position);
// intent.putExtra("detail", shopData);
Bundle bundle = new Bundle();
bundle.putSerializable("shop", shopData);
intent.putExtra("detail", shopData);
intent.setClass(MainActivity.this, DetailShopActivity.class);
MainActivity.this.startActivity(intent);

取值的时候:

<span style="white-space:pre">		</span>Intent intent = getIntent();
// ShopData data = intent.getParcelableExtra("detail");
ShopData data = (ShopData)intent.getSerializableExtra("detail");

对于另外一种方式:

import android.os.Parcel;
import android.os.Parcelable; public class ShopData implements Parcelable{ public String shopId;
public String name;
public String url;
public String info; public ShopData(Parcel in) {
readFromParcel(in);
} public ShopData() {
} public static final Parcelable.Creator<ShopData> CREATOR = new Parcelable.Creator<ShopData>() { public ShopData createFromParcel( Parcel in ){
return new ShopData(in);
} public ShopData[] newArray( int size){
return new ShopData[size];
}
}; @Override
public int describeContents() {
return 0;
} @Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(shopId);
dest.writeString(name);
dest.writeString(url);
dest.writeString(info); }
public void readFromParcel( Parcel in ){
shopId = in.readString();
name = in.readString();
url = in.readString();
info = in.readString();
} }

传递的时候这样写:

	<span style="white-space:pre">			</span>Intent intent = new Intent();
ShopData shopData = (ShopData)mAdapter.getItem(position);
intent.putExtra("detail", shopData);
intent.putExtra("detail", shopData);
intent.setClass(MainActivity.this, DetailShopActivity.class);
MainActivity.this.startActivity(intent);

取值的时候:

<span style="white-space:pre">		</span>Intent intent = getIntent();
ShopData data = intent.getParcelableExtra("detail");

android页面间传递对象的更多相关文章

  1. .net中常用的几种页面间传递参数的方法

    转自:http://www.cnblogs.com/lxshanye/archive/2013/04/11/3014207.html 参考:http://www.cnblogs.com/zhangka ...

  2. JSP页面间传递参数的5种方法

    JSP页面间传递参数是经常需要使用到的功能,有时还需要多个JSP页面间传递参数.下面介绍一下实现的方法. (1)直接在URL请求后添加 如:< a href="thexuan.jsp? ...

  3. jsp 页面间传递参数

    JSP页面间传递参数是经常需要使用到的功能,有时还需要多个JSP页面间传递参数.下面介绍一下实现的方法. (1)直接在URL请求后添加 如:< a href="thexuan.jsp? ...

  4. 在微信小程序页面间传递数据总结

    在微信小程序页面间传递数据 原文链接:https://www.jianshu.com/p/dae1bac5fc75 在开发微信小程序过程之中,遇到这么一些需要在微信小程序页面之间进行数据的传递的情况, ...

  5. jsp页面间传递参数 中文乱码问题(zz)

      jsp页面间传递参数 中文乱码问题 1.传递参数 var url = "*****Test.jsp?param1="+encodeURI(encodeURI(str));//对 ...

  6. ios页面间传递参数四种方式

    ios页面间传递参数四种方式 1.使用SharedApplication,定义一个变量来传递. 2.使用文件,或者NSUserdefault来传递 3.通过一个单例的class来传递 4.通过Dele ...

  7. localstroge可以在页面间传递数值;

    连接地址为:http://4.suancai.sinaapp.com/localstorg/a.html 原理是,a页面设置了sessionstorge,b页面可以访问到; 并且已关闭浏览器,sest ...

  8. StoryBoard学习(5):使用segue页面间传递数据

    StoryBoard学习(5):使用segue页面间传递数据 函数: - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sen ...

  9. Java WEB 之页面间传递特殊字符

    本文是学习网络上的文章时的总结以及自己的一点实践.感谢大家无私的分享. 昨天在做项目的时候,有一个页面间传递特殊字符的需求,查了一些资料.如今将自己的经验写出来. 首先.在前台编码 var fckPu ...

随机推荐

  1. LiveScript 函数

    The LiveScript Book     The LiveScript Book 函数 定义函数是非常轻量级的. 1.(x, y) -> x + y2.3.-> # an empty ...

  2. Android中如何截取字符串中某个字符之前或之后的字符串

    代码改变世界 Android中如何截取字符串中某个字符之前或之后的字符串 //截取#之前的字符串 String str = "sdfs#d"; str.substring(0, s ...

  3. 设计模式(一)单例模式:1-饿汉模式(Eager)

    思想: 饿汉模式是最常提及的2种单例模式之一,其核心思想,是类持有一个自身的 instance 属性,并且在申明的同时立即初始化. 同时,类将自身的构造器权限设为 private,防止外部代码创建对象 ...

  4. jquery validate用法总结

    jquery validate是本人用过的最好用的验证组件,但其文档写的真是不敢恭维,现将一些常见用法总结如下(持续更新). 1. js触发表单验证 //触发整个表单的验证 $('form').val ...

  5. 刷题总结——you are the one(hdu4283)

    题目: The TV shows such as You Are the One has been very popular. In order to meet the need of boys wh ...

  6. python object与dict互相转换

    代码如下 # 将class转dict,以_开头的属性不要 def props(obj): pr = {} for name in dir(obj): value = getattr(obj, name ...

  7. 2015-2016 ACM-ICPC Northeastern European Regional Contest (NEERC 15)

    NEERC 15 题解1 题解2 官方题解

  8. CodeForces 232E.Quick Tortoise

    John Doe has a field, which is a rectangular table of size n × m. We assume that the field rows are ...

  9. ado:SqlDataAdapter,dataset 与SqlDataReader的用法一

    原文发布时间为:2008-08-01 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...

  10. 浅谈JS的arguments对象

    在JavaScript中,arguments属于当前对象的一个内置属性,arguments非常类似于Array对象,但是又不是实例的Array.比如: Array.prototype.testArg ...