If you're just passing objects around then Parcelable was designed for this. It requires a little more effort to use than using Java's native serialization, but it's way faster (and I mean way,WAY faster).

From the docs, a simple example for how to implement is:

// simple class that just has one member property as an example public class MyParcelable implements Parcelable {   private int mData;   /* everything below here is for implementing Parcelable */   // 99.9% of the time you can just ignore this   public int describeContents() {     return 0;   }   // write your object's data to the passed-in Parcel   public void writeToParcel(Parcel out, int flags) {     out.writeInt(mData);   }   // this is used to regenerate your object. All Parcelables must have a CREATOR that implements these two methods   public static final Parcelable.Creator<MyParcelable> CREATOR = new Parcelable.Creator<MyParcelable>() {     public MyParcelable createFromParcel(Parcel in) {       return new MyParcelable(in);     }     public MyParcelable[] newArray(int size) {       return new MyParcelable[size];     }   };   // example constructor that takes a Parcel and gives you an object populated with it's values   private MyParcelable(Parcel in) {     mData = in.readInt();   } } 

Once you have your objects implement Parcelable it's just a matter of putting them into yourIntents with putExtra():

Intent i = new Intent(); i.putExtra("name_of_extra", myParcelableObject); 

Then you can pull them back out with getParcelableExtra():

Intent i = getIntent(); MyParcelable myParcelableObject = (MyParcelable) i.getParcelableExtra("name_of_extra"); 

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. android中AudioRecord使用详解
  2. android五种布局模式
  3. 【Android学习笔记】AutoCompleteTextVie
  4. Android timer
  5. 如何在Android平板电脑POWER按钮菜单中添
  6. 【Android】利用adt-bundle在Linux下轻松
  7. android framework 输入事件分析
  8. Android已有项目接入Flutter及互相通信
  9. 【EditText】Android 中设置 EditText 光
  10. 【Android(安卓)Linux内存及性能优化】(