http://developer.android.com/reference/android/os/Parcelable.html

A Activity

调用,PoiResultActivity

Intent intent = new Intent();intent.setClass(this, PoiResultActivity.class);Bundle bundle = new Bundle();ArrayList allPoiInfo = new ArrayList();ArrayList allPoi = result.getAllPoi();for (MKPoiInfo poiInfo : allPoi) {allPoiInfo.add(new PoiInfoParcelable(poiInfo));}bundle.putParcelableArrayList(MAP_ALL_POI_RESULT, allPoiInfo);intent.putExtras(bundle);startActivityForResult(intent, CODE_POI_RESULT);
@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {if (resultCode == CODE_POI_INFO_PARCELABLE) {PoiInfoParcelable poiInfo = (PoiInfoParcelable) data.getExtras().get(MAP_SELECTED_POI_INFO);int position = data.getExtras().getInt(MAP_SELECTED_POI_INFO_POSITION);moveToMyLocation(poiInfo.pt);mPoioverlay.setShowPopView(position);}super.onActivityResult(requestCode, resultCode, data);}

PoiResultActivity接受

private void bindData() {Bundle bundle = getIntent().getExtras();ArrayList allPoiResult =  bundle.getParcelableArrayList(MAP_ALL_POI_RESULT);PoiResultItemAdapter adapter = new PoiResultItemAdapter(this, allPoiResult);mListView.setAdapter(adapter);}

PoiResultActivity返回到A Activity

Intent intent = new Intent();intent.putExtra(MAP_SELECTED_POI_INFO_POSITION, position);intent.putExtra(MAP_SELECTED_POI_INFO, (PoiInfoParcelable)obj);setResult(CODE_POI_INFO_PARCELABLE, intent);finish();

这个地方应为我要传递一个百度地图的地理信息去下个Activity中,所以直接从MKPoiInfo继承了

public class PoiInfoParcelable extends MKPoiInfo implements Parcelable {public PoiInfoParcelable(){}public PoiInfoParcelable(MKPoiInfo poiInfo) {this.address = poiInfo.address;this.city = poiInfo.city;this.ePoiType = poiInfo.ePoiType;this.name = poiInfo.name;this.phoneNum = poiInfo.phoneNum;this.postCode = poiInfo.postCode;this.pt = poiInfo.pt;}@Overridepublic int describeContents() {return 0;}@Overridepublic void writeToParcel(Parcel dest, int flags) {dest.writeString(this.address);dest.writeString(this.city);dest.writeString(this.name);dest.writeString(this.phoneNum);dest.writeString(this.postCode);dest.writeInt(this.ePoiType);dest.writeInt(this.pt.getLatitudeE6());dest.writeInt(this.pt.getLongitudeE6());}public final static Parcelable.Creator CREATOR = new Creator() {@Overridepublic PoiInfoParcelable[] newArray(int size) {return new PoiInfoParcelable[size];}@Overridepublic PoiInfoParcelable createFromParcel(Parcel source) {PoiInfoParcelable poiInfo = new PoiInfoParcelable();poiInfo.address = source.readString();poiInfo.city = source.readString();poiInfo.name = source.readString();poiInfo.phoneNum = source.readString();poiInfo.postCode = source.readString();poiInfo.ePoiType = source.readInt();poiInfo.pt = new GeoPoint(source.readInt(), source.readInt());return poiInfo;}};}

如果是复杂的情况,就是N多的参数,可以用下面这种方式

public class PoiResultParcelable implements Parcelable {private ArrayList poiInfoList;public ArrayList getPoiInfoList() {return poiInfoList;}public void setPoiInfoList(ArrayList poiInfoList) {this.poiInfoList = poiInfoList;}public PoiResultParcelable(Parcel in) {readFromParcel(in);}private void readFromParcel(Parcel in) {in.readTypedList(poiInfoList, PoiInfoParcelable.CREATOR);}@Overridepublic int describeContents() {return poiInfoList == null ? 0 : poiInfoList.size();}@Overridepublic void writeToParcel(Parcel dest, int flags) {dest.writeList(poiInfoList);}public final static Parcelable.Creator CREATOR = new Creator() {@Overridepublic PoiResultParcelable[] newArray(int size) {return new PoiResultParcelable[size];}@Overridepublic PoiResultParcelable createFromParcel(Parcel source) {PoiResultParcelable poiResult = new PoiResultParcelable(source);return poiResult;}};}

  

 

更多相关文章

  1. android 调用本地音乐播放器
  2. Android的一些基本常识
  3. android string.xml占位符
  4. Android(安卓)程序调用系统发信息程序
  5. 在android里面调用javascript代码
  6. Android路径大全
  7. android listview 调用sqlsite数据库显示数据
  8. Android(安卓)Fragment
  9. Android(安卓)Studio Run程序时自动执行自定义task

随机推荐

  1. Android(安卓)关于App被杀死后,如何接收极
  2. Android当中的MVP模式(六)View 层 Activity
  3. Android零基础入门第11节:简单几步带你飞,
  4. Android(安卓)提示Your project contains
  5. 中国iOS和Android设备激活量将超美国
  6. Android React Native使用原生UI组件
  7. Android_常驻进程(杀不死的进程)
  8. Android 脚本设计之 SL4A
  9. [笔记] android/iOS自动化测试神器Appium
  10. Android使用ViewFlipper实现图片切换功能