我有这个课:
public class FlightData implements Parcelable { private double x; private double y; private double time;
FlightData(double x, double y, double time){
this.x = x;
this.y = y;
this.time = time;
}
private FlightData(Parcel in) {
x = in.readDouble();
y = in.readDouble();
time = in.readDouble();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeDouble(x);
dest.writeDouble(y);
dest.writeDouble(time);
}
public static final Creator<FlightData> CREATOR = new Creator<FlightData>() {
@Override
public FlightData createFromParcel(Parcel in) {
return new FlightData(in);
}
@Override
public FlightData[] newArray(int size) {
return new FlightData[size];
}
};
...
} 我尝试将其打包,然后是意图。但是我什至无法在同一个活动中检索它(它在另一个活动中抛出null,所以我也尝试在当前活动中获取它-null):
List<FlightData> flightDataList = new ArrayList<>();
//... arraylist gets filled in
intent = new Intent(this, DatasheetActivity.class);
bundle = new Bundle();
bundle.putParcelableArrayList("FlightDataList", (ArrayList<? extends Parcelable>) flightDataList);
intent.putExtra("Bundle", bundle);
Log.d("ErrorCustom",Integer.toString(flightDataList.size()));
//Log.d("ErrorCustom",Integer.toString(intent.getExtras().getParcelableArrayList("FlightDataList").size())); //throws null error
startActivity(intent);
我确实想发送ArrayList,因为它被填充在当前活动中(带有进度条)。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。