2010-09-21 85 views
2

我正在嘗試將Task parcelable放入一個捆綁包中,以便將其從我的服務傳遞到活動,但我在處理我的自定義類型的ArrayList時遇到了一些麻煩。Make Class Parcelable error

任務:

@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> 

如果資源是實現Parcelable然後我沒有看到問題出在哪裏。

編輯:我相信我固定了這部分。我用.writeParcelableList()INSTEAD。有人可以證實這種方法可行嗎?下面的問題仍然有效。

此外,當活動從意圖讀取任務時,我需要做一些計算來填充其他數據成員。什麼函數被稱爲那裏,我可以impliment做計算?它是readFromParcel(...)還是將Parcelable作爲參數的構造函數?

感謝

回答

3

toArray()返回一個類型的Object[],這就是爲什麼你得到:

對象不是有界參數

對象不延長有效的替代品Parcelable。你必須轉換toArray()電話:

(Resources[])resources.toArray() 

正如你所說的,因爲資源實現Parcelable,這應該擺脫你的異常。

相關問題