我首先会说我已经看过所有其他处理这个问题的帖子并尝试了所有这些帖子。
我正在尝试做与其他帖子中要求的相同的事情,即使用 Intent 将 ArrayList 的值从一个活动传递到另一个活动。
我觉得我已经正确地实施了我的课程。我正在使用的主要类(Route_Class)如下。
public static final Parcelable.Creator<Route_Class> CREATOR =
new Parcelable.Creator<Route_Class>()
public Route_Class createFromParcel(Parcel in)
{
System.out.println("in Parcel In");
Route_Class route_class = new Route_Class();
route_class.layout_width2 = in.readString();
route_class.latitude = in.readDouble();
route_class.longitude = in.readDouble();
route_class.startingLat = in.readDouble();
route_class.startingLong = in.readDouble();
route_class.name = in.readString();
route_class.routeName = in.readString();
route_class.GeoPoints = in.readString();
route_class.layout_width = in.readString();
route_class.layout_height = in.readString();
route_class.orientation = in.readString();
route_class.xmlns = in.readString();
route_class.id = in.readString();
route_class.clickable = in.readInt() == 0;
route_class.enabled = in.readInt() == 0;
route_class.layout_height2 = in.readString();
route_class.apiKey = in.readString();
Bundle b = in.readBundle(GeoPoints_Class.class.getClassLoader());
route_class.geoPoints_arraylist = b.getParcelableArrayList("_geoPoints_arraylist");
return route_class;
}
@Override
public Route_Class[] newArray(int size)
{
return new Route_Class[size];
}
};
这是我在 Route_Class 中使用的第二个类 (GeoPoints_Class)。
public static final Parcelable.Creator<GeoPoints_Class> CREATOR =
new Parcelable.Creator<GeoPoints_Class>()
{
public GeoPoints_Class createFromParcel(Parcel in) {
GeoPoints_Class geoPoints_class = new GeoPoints_Class();
System.out.println("In Parcel In for GEoPoints");
geoPoints_class.lat = in.readDouble();
geoPoints_class.lon = in.readDouble();
geoPoints_class.location = in.readString();
return geoPoints_class;
接下来是我放置对象的地方..
Intent i = new Intent(getApplicationContext(), route.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle b = new Bundle();
b.putParcelableArrayList("route_Classes_temp", route_Classes);
i.putExtra("selectiontemp",parent.getItemAtPosition(pos).toString());
i.putExtras(b);
startActivityForResult(i, 100);
最后,我尝试获取对象的地方...
Bundle b = this.getIntent().getExtras();
route_Classes = b.getParcelableArrayList("route_Classes_temp");
userMapSelection = b.getString("selectiontemp");
我一直在尝试将其用作资源:http ://androidideasblog.blogspot.com/2010/02/passing-list-of-objects-between.html但它似乎不起作用。运行应用程序时出现以下错误(任何线索错误的幻数引用的是什么?):
11-09 14:48:52.951: E/Bundle(1128): readBundle: trace = java.lang.RuntimeException
11-09 14:48:52.951: E/Bundle(1128): at android.os.Bundle.readFromParcelInner(Bundle.java:1580)
11-09 14:48:52.951: E/Bundle(1128): at android.os.Bundle.<init>(Bundle.java:82)
11-09 14:48:52.951: E/Bundle(1128): at android.os.Parcel.readBundle(Parcel.java:1381)
提前致谢!