views:

59

answers:

1

I am trying to make Task parcelable to put into an bundle to pass from my service to activity but I'm having a little bit of trouble working with the ArrayList of my custom type.

Task:

@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);
}

Resource:

@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);
}

It gives me an error on the prc.writeTypedArray function inside task:

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>

If Resources is implementing Parcelable then I don't see where the problem is.

Edit: I BELIEVE I FIXED THIS PART. I USED .writeParcelableList() INSTEAD. CAN SOMEONE CONFIRM THAT THIS SHOULD WORK? QUESTION BELOW IS STILL VALID.

Also when Task is read from the intent by the activity, I need to do some computation to fill some other data members. What function is called there that I can impliment to do the computation? Is it readFromParcel(...) or the constructor that takes in a Parcelable as a parameter?

Thanks

+1  A: 

toArray() returns a type of Object[], which is why you're getting:

Object is not a valid substitute for the bounded parameter

Object does not extend Parcelable. You must cast the toArray() call:

(Resources[])resources.toArray()

As you said, since Resources implements Parcelable, this should get rid of your exception.

McStretch