3 回答
TA贡献1851条经验 获得超3个赞
我怀疑您是否在 FlightData 中实现了 Parcable https://medium.com/techmacademy/how-to-implement-and-use-a-parcelable-class-in-android-part-1-28cca73fc2d1
TA贡献2016条经验 获得超9个赞
它应该有效。我在你的例子中唯一缺少的是构造函数。它可以解释null你所得到的。
尝试添加这个构造函数FlightData
public FlightData(Parcel in) {
x = in.readDouble();
y = in.readDouble();
time = in.readDouble();
}
TA贡献1785条经验 获得超4个赞
您是否尝试创建一个实现 Parcelable 的数据结构?
public class flightDataList implements Parcelable{
String dataThingyString;
int dataThingyInt;
public flightDataList(String dataThingyString, int dataThingyInt){
this.dataThingyString = dataThingyString;
this.dataThingyInt = dataThingyInt;
}
public flightDataList(Parcle in){
this.dataThingyString = in.readString();
this.dataThingyInt = in.readInt();
}
@Override
public void writeToParcel(Parcel dest, int flags){
dest.writeString(dataThingyString);
dest.writeInt(dataThingyInt);
}
public static final Creator<flightDataList> CREATOR = new Creator<flightDataList>(){
@Override
public flightDataList createFromParcel(Parcel source){
return new flightDataList(source);
}
@Override
public flightDataList[] newArray(int size){
return new flightDataList[size];
}
}
public void setdataThingyString(String stringData){
this.dataThingyString = stringData;
}
public void setdataThingyInt(int intData){
this.dataThingyInt = intData;
}
public String getdataThingyString(){
return dataThingyString;
}
public int getdataThingyInt(){
return dataThingyInt;
}
@Override
public int describeContents(){
return 0;
}
}
TA贡献1799条经验 获得超8个赞
1.首先在FlightData对象模型/pojo/class中实现Parceable
2.val flightDataList= ArrayList<FlightData>()
3.val args = Bundle()
4.args.putParcelableArrayList("FlightDataList", flightDataList)
5.intent.putExtra(args)
然后获取列表
val flightDataList = context.getIntent().getExtras().getParcelableArrayList("FlightDataList")
添加回答
举报