首页 > 其他分享 >Parcelable传递图片,复杂对象,对象列表

Parcelable传递图片,复杂对象,对象列表

时间:2023-04-07 10:06:50浏览次数:49  
标签:return String 对象 Parcelable 列表 dest field public md5


package com.ql.model;

import android.os.Parcel;
import android.os.Parcelable;

public class Stock implements Parcelable{

	private String field_0;//代码+\n+名称
	private String field_1;//最新+\n+金额
	private String field_2;//涨幅
	private String field_3;//涨跌
	private String field_4;//雷达
	//分时
	private float[] field_5;//走势
	private String field_6;//高点
	private String field_7;//均线
	private String field_8;//低点
	public Stock(){
		
	}
	public Stock(String field_0, String field_1, String field_2,
			String field_3, String field_4, float[] field_5, String field_6,
			String field_7, String field_8) {
		super();
		this.field_0 = field_0;
		this.field_1 = field_1;
		this.field_2 = field_2;
		this.field_3 = field_3;
		this.field_4 = field_4;
		this.field_5 = field_5;
		this.field_6 = field_6;
		this.field_7 = field_7;
		this.field_8 = field_8;
	}
	public String getField_6() {
		return field_6;
	}
	public void setField_6(String field_6) {
		this.field_6 = field_6;
	}
	public String getField_7() {
		return field_7;
	}
	public void setField_7(String field_7) {
		this.field_7 = field_7;
	}
	public String getField_8() {
		return field_8;
	}
	public void setField_8(String field_8) {
		this.field_8 = field_8;
	}
	public float[] getField_5() {
		return field_5;
	}
	public void setField_5(float[] field_5) {
		this.field_5 = field_5;
	}
	public String getField_0() {
		return field_0;
	}
	public void setField_0(String field_0) {
		this.field_0 = field_0;
	}
	public String getField_1() {
		return field_1;
	}
	public void setField_1(String field_1) {
		this.field_1 = field_1;
	}
	public String getField_2() {
		return field_2;
	}
	public void setField_2(String field_2) {
		this.field_2 = field_2;
	}
	public String getField_3() {
		return field_3;
	}
	public void setField_3(String field_3) {
		this.field_3 = field_3;
	}
	public String getField_4() {
		return field_4;
	}
	public void setField_4(String field_4) {
		this.field_4 = field_4;
	}
	public static Parcelable.Creator getCreator() {
		return CREATOR;
	}
	@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.writeString(field_0);  
		dest.writeString(field_1);  
		dest.writeString(field_2);  
		dest.writeString(field_3);  
        dest.writeString(field_4);
        dest.writeFloatArray(field_5);
        dest.writeString(field_6);
        dest.writeString(field_7);
        dest.writeString(field_8);
	}
	public Stock(Parcel in)  
    {  
        this.field_0 = in.readString();  
        this.field_1 = in.readString();  
        this.field_2 = in.readString();
        this.field_3 = in.readString();
        this.field_4 = in.readString();
//        in.readFloatArray(this.field_5);//似乎不行
        this.field_5=in.createFloatArray();//可能不妥,看API
        this.field_6 = in.readString();
        this.field_7 = in.readString();
        this.field_8 = in.readString();
    }  
   
    @SuppressWarnings("unchecked")  
    public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {  
        public Stock createFromParcel(Parcel in)  
        {  
            return new Stock(in);  
        }  
   
        public Stock[] newArray(int size)  
        {  
            return new Stock[size];  
        }  
    };  
}



//ArrayList<Stock> models={XXXXXXX};
//Intent intent=new Intent(MyStockActivity.this,MyStockSettingActivity.class);
//传递
intent.putParcelableArrayListExtra("sockets", models);
//startActivityForResult(intent, RESULT_CODE_SETTING);
//读取
models=getIntent().getParcelableArrayListExtra("sockets");




Android高手进阶教程(十七)之---Android中Intent传递对象的两种方法(Serializable,Parcelable)!




传递图片和复杂对象,复杂对象也需要实现Parcelable接口


package com.ata.model.receive;

import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;

public class Exam implements Parcelable{

	public String ad_md5;//
	public String buttons_md5;//
	public String etx_code;//考试编码
	public String faq_md5;//
	public String is_etx;//0否1是
	public String logo_url;//logourl
	public Bitmap bitmap;//logo_url对应的图标
	public String news_md5;//
	public String sample_md5;//
	public String sample_url;//邮汇样张url
	public String sort;//
	public String status;//状态
	public String test_name;//考试名称
	public String test_name_short;//
	public String test_sponsor;//主办者
	public String test_type;//考试类型
	public String test_date;//当前批次考试日期
	public String etx_id_desc;//当前批次说明
	public String intro_url;//考试介绍url
	public String test_notice;//考试提醒
	public String date_url;//考试日期
	public String etx_id;//
	public int is_hot;//热门考试
	public String account_notice;//帐号说明
	public Bind bind;//复杂对象,绑定信息

	public String getAccount_notice() {
		return account_notice;
	}
	public void setAccount_notice(String account_notice) {
		this.account_notice = account_notice;
	}
	public int getIs_hot() {
		return is_hot;
	}
	public void setIs_hot(int is_hot) {
		this.is_hot = is_hot;
	}
	public Bind getBind() {
		return bind;
	}
	public void setBind(Bind bind) {
		this.bind = bind;
	}
	public String getAd_md5() {
		return ad_md5;
	}
	public void setAd_md5(String ad_md5) {
		this.ad_md5 = ad_md5;
	}
	public String getButtons_md5() {
		return buttons_md5;
	}
	public void setButtons_md5(String buttons_md5) {
		this.buttons_md5 = buttons_md5;
	}
	public String getEtx_code() {
		return etx_code;
	}
	public void setEtx_code(String etx_code) {
		this.etx_code = etx_code;
	}
	public String getFaq_md5() {
		return faq_md5;
	}
	public void setFaq_md5(String faq_md5) {
		this.faq_md5 = faq_md5;
	}
	public String getIs_etx() {
		return is_etx;
	}
	public void setIs_etx(String is_etx) {
		this.is_etx = is_etx;
	}
	public String getLogo_url() {
		return logo_url;
	}
	public void setLogo_url(String logo_url) {
		this.logo_url = logo_url;
	}
	public String getNews_md5() {
		return news_md5;
	}
	public void setNews_md5(String news_md5) {
		this.news_md5 = news_md5;
	}
	public String getSample_md5() {
		return sample_md5;
	}
	public void setSample_md5(String sample_md5) {
		this.sample_md5 = sample_md5;
	}
	public String getSample_url() {
		return sample_url;
	}
	public void setSample_url(String sample_url) {
		this.sample_url = sample_url;
	}
	public String getSort() {
		return sort;
	}
	public void setSort(String sort) {
		this.sort = sort;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getTest_name() {
		return test_name;
	}
	public void setTest_name(String test_name) {
		this.test_name = test_name;
	}
	public String getTest_name_short() {
		return test_name_short;
	}
	public void setTest_name_short(String test_name_short) {
		this.test_name_short = test_name_short;
	}
	public String getTest_sponsor() {
		return test_sponsor;
	}
	public void setTest_sponsor(String test_sponsor) {
		this.test_sponsor = test_sponsor;
	}
	public String getTest_type() {
		return test_type;
	}
	public void setTest_type(String test_type) {
		this.test_type = test_type;
	}
	public String getTest_date() {
		return test_date;
	}
	public void setTest_date(String test_date) {
		this.test_date = test_date;
	}
	public String getEtx_id_desc() {
		return etx_id_desc;
	}
	public void setEtx_id_desc(String etx_id_desc) {
		this.etx_id_desc = etx_id_desc;
	}
	public String getIntro_url() {
		return intro_url;
	}
	public void setIntro_url(String intro_url) {
		this.intro_url = intro_url;
	}
	public String getTest_notice() {
		return test_notice;
	}
	public void setTest_notice(String test_notice) {
		this.test_notice = test_notice;
	}
	public String getDate_url() {
		return date_url;
	}
	public void setDate_url(String date_url) {
		this.date_url = date_url;
	}
	public String getEtx_id() {
		return etx_id;
	}
	public void setEtx_id(String etx_id) {
		this.etx_id = etx_id;
	}
	
	public Bitmap getBitmap() {
		return bitmap;
	}
	public void setBitmap(Bitmap bitmap) {
		this.bitmap = bitmap;
	}
	public static Parcelable.Creator<Exam> getCreator() {
		return CREATOR;
	}
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		dest.writeString(ad_md5);
		dest.writeString(buttons_md5);
		dest.writeString(etx_code);
		dest.writeString(faq_md5);
		dest.writeString(is_etx);
		dest.writeString(logo_url);
		bitmap.writeToParcel(dest, flags);
		dest.writeString(news_md5);
		dest.writeString(sample_md5);
		dest.writeString(sample_url);
		dest.writeString(sort);
		dest.writeString(status);
		dest.writeString(test_name);
		dest.writeString(test_name_short);
		dest.writeString(test_sponsor);
		dest.writeString(test_type);
		dest.writeString(test_date);
		dest.writeString(etx_id_desc);
		dest.writeString(intro_url);
		dest.writeString(test_notice);
		dest.writeString(date_url);
		dest.writeString(etx_id);
		dest.writeInt(is_hot);
		dest.writeString(account_notice);
		dest.writeParcelable(bind, flags);
	}
	public static final Parcelable.Creator<Exam> CREATOR = new Creator<Exam>() {
		public Exam createFromParcel(Parcel source) {
			Exam instance = new Exam();
			instance.ad_md5 = source.readString();
			instance.buttons_md5 = source.readString();
			instance.etx_code = source.readString();
			instance.faq_md5 = source.readString();
			instance.is_etx = source.readString();
			instance.logo_url = source.readString();
			instance.bitmap=Bitmap.CREATOR.createFromParcel(source);
			instance.news_md5 = source.readString();
			instance.sample_md5 = source.readString();
			instance.sample_url = source.readString();
			instance.sort = source.readString();
			instance.status = source.readString();
			instance.test_name = source.readString();
			instance.test_name_short = source.readString();
			instance.test_sponsor = source.readString();
			instance.test_type = source.readString();
			instance.test_date = source.readString();
			instance.etx_id_desc = source.readString();
			instance.intro_url = source.readString();
			instance.test_notice = source.readString();
			instance.date_url = source.readString();
			instance.etx_id = source.readString();
			instance.is_hot = source.readInt();
			instance.account_notice = source.readString();
			instance.bind=source.readParcelable(Bind.class.getClassLoader());
			return instance;
		}

		public Exam[] newArray(int size) {
			// TODO Auto-generated method stub
			return new Exam[size];
		}
	};
    
}




传递对象列表ArrayList<Queue>,Queue也要实现Parcelable


package com.reyo.model;

import java.util.ArrayList;

import android.os.Parcel;
import android.os.Parcelable;

public class QueueList implements Parcelable{

	public String mealName;
	public String startTime;
	public String endTime;
	public int timeType;
	public int flagType;
	public ArrayList<Queue> queueList;
	public String getMealName() {
		return mealName;
	}
	public void setMealName(String mealName) {
		this.mealName = mealName;
	}
	public String getStartTime() {
		return startTime;
	}
	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}
	public String getEndTime() {
		return endTime;
	}
	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}
	public int getTimeType() {
		return timeType;
	}
	public void setTimeType(int timeType) {
		this.timeType = timeType;
	}
	public int getFlagType() {
		return flagType;
	}
	public void setFlagType(int flagType) {
		this.flagType = flagType;
	}
	public ArrayList<Queue> getQueueList() {
		return queueList;
	}
	public void setQueueList(ArrayList<Queue> queueList) {
		this.queueList = queueList;
	}
	
	public static Parcelable.Creator<QueueList> getCreator() {
		return CREATOR;
	}
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		dest.writeString(mealName);
		dest.writeString(startTime);
		dest.writeString(endTime);
		dest.writeInt(timeType);
		dest.writeInt(flagType);
		dest.writeList(queueList);
	}
	public static final Parcelable.Creator<QueueList> CREATOR = new Creator<QueueList>() {
		public QueueList createFromParcel(Parcel source) {
			QueueList instance = new QueueList();
			instance.mealName = source.readString();
			instance.startTime = source.readString();
			instance.endTime = source.readString();
			instance.timeType = source.readInt();
			instance.flagType = source.readInt();
			instance.queueList=source.readArrayList(Queue.class.getClassLoader());
			return instance;
		}

		public QueueList[] newArray(int size) {
			// TODO Auto-generated method stub
			return new QueueList[size];
		}
	};
	
}



Android中传递对象的三种方法


http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0104/2256.html


标签:return,String,对象,Parcelable,列表,dest,field,public,md5
From: https://blog.51cto.com/u_5454003/6174584

相关文章

  • Java GenericObjectPool 对象池化技术--SpringBoot sftp 连接池工具类
    JavaBasePooledObjectFactory对象池化技术通常一个对象创建、销毁非常耗时的时候,我们不会频繁的创建和销毁它,而是考虑复用。复用对象的一种做法就是对象池,将创建好的对象放入池中维护起来,下次再用的时候直接拿池中已经创建好的对象继续用,这就是池化的思想。ApacheCommonsPoo......
  • Java面向对象继承
    继承的概念继承是面向对象编程中的一个概念,它允许一个类(称为子类或派生类)继承另一个类(称为父类或基类)的属性和方法。子类在继承父类的同时也可以添加自己的属性和方法,从而实现代码的复用和扩展。继承是面向对象编程的三大特征之一,其他两个分别是封装和多态。继承的作用1.提高代码的......
  • 常见API,对象克隆
    目录学习目标1Math类1.1概述1.2常见方法1.3算法小题(质数)1.4算法小题(自幂数)1.5课后练习2System类2.1概述2.2常见方法3Runtime3.1概述3.2常见方法3.3恶搞好基友4Object类4.1概述4.2常见方法5Objects类5.1概述5.2常见方法6BigInteger类6.1引入6.2概述6.3......
  • 列表 增删改查
    1.列表.append(元素)向列表追加元素2.列表.extend(元素)将数据容器的内容一次取出,追加到元素的尾部3.列表.insert(下标,元素)在指定下标处,插入指定的元素4.del列表[下标]删除列表指定下标元素5.列表.pop(下标)删除列表指定下标元素6.列表.remove(元素)从前向后,删除此元......
  • flask请求上下文分析,源码request原理,wtforms,精确导出依赖,函数和方法,threading.locl对
    内容回顾蓝图第一步:导入第二步:实例化得到对象,可以指定static和templates第三步:app中注册蓝图,注册蓝图时,可以指定前缀第四步:使用蓝图,注册路由,注册请求扩展g对象当次请求的全局对象,在当次请求中可以放值和取值跟session的区别是session可以在多次请求中使用,g对象只在当次请......
  • 两个对象值相同(x.equals(y) == true),但却可有不同的hash code
    当我们使用Java的hashCode()方法时,该方法将返回与该对象相关的一个整数值。hashcode用于在哈希表等数据结构中确定对象的位置,以提高查找效率。当我们使用equals()方法比较两个对象时,如果equals()返回true,则可以认为这两个对象的值相等。然而,有时候两个对象值相同,但它们......
  • flask之请求上下文分析之导出项目依赖-函数和方法的区别-threading.local对象-偏函数-
    目录flask之请求上下文分析之导出项目依赖-函数和方法的区别-threading.local对象-偏函数-flask整个生命执行流程--wtforms今日内容详细1请求上下文分析(源码:request原理)1.1导出项目的依赖1.2函数和方法1.3threading.local对象1.4偏函数1.5flask整个生命执行流程(1.1.4版本......
  • Page 对象与 list 对象的相互转换
    转载:Page对象与list对象的相互转换_page转list_ajungejava的博客-CSDN博客我们有的时候会用到分页,使用page对象,但是在处理逻辑中常常需要list对象和page对象的转换Page-->Listpage.getcontent();返回的是list<object>List-->PagenewpageImpl(List<Object>co......
  • flask-day4——pipreqs模块、函数和方法的区别、threading.local对象、偏函数、flask
    目录一、请求上下文分析(源码:request原理)1.1导出项目的依赖(pipreqs模块)1.2函数和方法1.3threading.local对象代码演示自定义封装local,实现兼容线程和协程1.4偏函数1.5flask整个生命执行流程(1.1.4版本为例)二、wtforms(了解)三、作业1、为什么有了gil锁还要互斥锁2、什么是进程,线......
  • 请求上下文分析、函数和方法、threading.local对象、偏函数、flask整个生命执行流程(1
    请求上下文分析(源码:request原理)导出项目的依赖#之前pipfreeze>requirments.txt把当前解释器环境下的所有第三方依赖都导出来#使用第三方模块,更精确的导出依赖pipreqs第一步:安装pip3installpipreqs第二步:使用命令,导出项目依赖pipreqs./w......