我正在尝试使 Task parcelable 放入一个包中以从我的服务传递到活动,但我在使用我的自定义类型的 ArrayList 时遇到了一些麻烦。
任务:
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel prc, int arg1) {
// TODO Auto-generated method stub
prc.writeInt(id);
prc.writeString(timeStamp_string);
prc.writeString(timeToComplete_string);
prc.writeTypedArray(resources.toArray(), PARCELABLE_WRITE_RETURN_VALUE);
}
资源:
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel prc, int flags) {
// TODO Auto-generated method stub
prc.writeInt(id);
prc.writeString(timeStamp_string);
prc.writeString(resourceType);
prc.writeString(dataType);
prc.writeString(value);
prc.writeInt(taskId);
}
它在任务内的 prc.writeTypedArray 函数上给了我一个错误:
Bound mismatch: The generic method writeTypedArray(T[], int) of type Parcel is not applicable for the arguments (Object[], int). The inferred type Object is not a valid substitute for the bounded parameter <T extends Parcelable>
如果 Resources 正在实施 Parcelable,那么我看不出问题出在哪里。
编辑:我相信我已经修复了这部分。我使用 .writeParcelableList() 代替。有人可以确认这应该有效吗?下面的问题仍然有效。
此外,当活动从意图中读取任务时,我需要进行一些计算来填充其他一些数据成员。在那里调用什么函数可以实现计算?是 readFromParcel(...) 还是以 Parcelable 作为参数的构造函数?
谢谢