Android---Intent传送复杂数据
来源:互联网 发布:英菲克直播软件 编辑:程序博客网 时间:2024/05/22 14:01
1. 实现序列化接口的Model类
/** * */package com.aaron.util;import java.io.Serializable;import android.os.Parcel;import android.os.Parcelable;/** * @author aaron * */public class Model implements Serializable{ /** * */ private static final long serialVersionUID = -6680457902587956425L; private int month; private float total; private String store; /** * @return the month */ public int getMonth() { return month; } /** * @param month the month to set */ public void setMonth(int month) { this.month = month; } /** * @return the total */ public float getTotal() { return total; } /** * @param total the total to set */ public void setTotal(float total) { this.total = total; } /** * @return the store */ public String getStore() { return store; } /** * @param store the store to set */ public void setStore(String store) { this.store = store; }}
强制序列化代码:
//通过Intent传送数据 Intent intent = new Intent(); intent.putExtra("Model", (Serializable)list); intent.setClass(NetClientDemoActivity.this, HelloAchartengineActivity.class); NetClientDemoActivity.this.startActivity(intent);
接收数据:
//获取Intent传送过来的数据 Intent intent = getIntent(); List<Model> list = (List<Model>) intent.getSerializableExtra("Model"); String[] titles = new String[]{list.get(0).getStore()};
2. Parcelable实现List传输
Parcelable序列化了的POJO类:
/** * */package com.aaron.util;import android.os.Parcel;import android.os.Parcelable;/** * @author aaron * */public class Model implements Parcelable { private int month; private float total; private String store; /** * @return the month */ public int getMonth() { return month; } /** * @param month * the month to set */ public void setMonth(int month) { this.month = month; } /** * @return the total */ public float getTotal() { return total; } /** * @param total * the total to set */ public void setTotal(float total) { this.total = total; } /** * @return the store */ public String getStore() { return store; } /** * @param store * the store to set */ public void setStore(String store) { this.store = store; } @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.writeInt(month); dest.writeString(store); dest.writeFloat(total); } public static final Parcelable.Creator<Model> CREATOR = new Parcelable.Creator<Model>() { @Override public Model createFromParcel(Parcel source) { // TODO Auto-generated method stub Model model = new Model(); model.month = source.readInt(); model.store = source.readString(); model.total = source.readFloat(); return model; } @Override public Model[] newArray(int size) { // TODO Auto-generated method stub return new Model[size]; } };}
Parcelable序列化Parcelable序列化需要注意的是,需要重载describeContents()、writeToParcel(Parcel dest, int flags)、Parcelable.Creator CREATOR = new Parcelable.Creator()这三个方法。
Parcelable数据传递代码:
//Parcelable实现序列化传送数据 Intent intent = new Intent(); intent.putParcelableArrayListExtra("Model", (ArrayList<? extends Parcelable>) list); intent.setClass(NetClientDemoActivity.this, HelloAchartengineActivity.class);
Parcelable接收数据代码:
//通过Parcelable反序列化获取数据 Intent intent = getIntent(); List<Model> list = intent.getParcelableArrayListExtra("Model"); String[] titles = new String[]{list.get(0).getStore()};
原文链接这里写链接内容
0 0
- Android---Intent传送复杂数据
- android中的Intent于Activity的数据传送
- Android 通过intent跳转页面并传送数据
- android之Intent传递复杂数据时的注意事项
- Android例子—Intent之复杂数据的传递
- Intent复杂数据的传递
- 利用Intent传递复杂数据
- PendingIntent Intent 传送数据 为null
- 多类带数据传送的Intent实现方法
- JSON实现Android 网络数据交换(包括复杂对象的传送)
- Android对话框传送数据
- android数据加密传送
- android之Intent复杂数据的传递(ArrayList<String>类型的数据)
- android之Intent复杂数据的传递一(Object类型的数据)
- android之Intent复杂数据的传递二(Object类型的数据)
- android之Intent复杂数据的传递(ArrayList<Object>类型的数据)
- Intent传递复杂数据的问题
- Intent之复杂数据的传递
- 状态模式
- Matconvnet 的安装以及使用
- Exception: Traceback (most recent call last): File "/Library/Python/2.7/site-packages/pip-9.0.1-py
- 远程打码是什么意思
- 次方数列
- Android---Intent传送复杂数据
- 安卓使用平板在activity的设置启动页的横竖屏显示
- asp.net 中使用JQuery Ajax 上传文件
- Android中ContentProvider组件详解
- dbms_stats
- php无限级分类实现方法分析
- 21种设计模式理论版
- 任意位置生成右键自定义菜单插件context.js之API与调用
- Android开源项目推荐之【角标“徽章”简介】