I've been pondering some more and come up with two workarounds useful if anyone else is in the same boat:
1) (Inspired by CommonsWare) Put a flag on each part of the chain to indicate direction Up the heirarchy is lossy in the sense that all items to the ContainerClass cannot be restored.
class ContainerClass implements Parcelable {
boolean _parcelableDownHeirarchy = true;
List<ItemClass> _items;
(...)
private ContainerClass( Parcel in ) {
_items = in.readArrayList( ItemClass.class.getClassLoader() );
(...)
if ( _parcelableDownHierarchy ) {
for ( int i = 0; i < _items.size(); i++ )
_items.get( i ).set_container( this );
}
}
public void writeToParcel( Parcel p, int args ) {
p.writeByte( (byte)_parcelableDownHierarchy ? 1 : 0 );
if ( _parcelableDownHeirarchy )
p.writeList( _items );
(...)
}
}
class ItemClass implements Parcelable {
boolean _parcelableDownHeirarchy = true;
ContainerClass _containerRef;
(...)
private ItemClass( Parcel in ) {
if ( !_parcelableDownHeirarchy ) {
_containerRef = in.readParcelable( ContainerClass.class.getClassLoader() );
//Won't contain item in it's _items list.
}
}
public void writeToParcel( Parcel p, int args ) {
p.writeByte( (byte)_parcelableDownHierarchy ? 1 : 0 );
if ( !_parcelableDownHeirarchy ) //Up the heirarchy
p.writeParcelable( _containerRef );
(...)
}
}
2) Hackish workaround, employing a static hash table, granted each object can be uniquely identified by it's parcelable attributes. (In my case I have the primary key in my database in the objects).
class ContainerClass implements Parcelable {
//Leave be
}
class ItemClass implements Parcelable {
HaspMap<Long, ContainerClass> _parents = new HashMap<Long, ContainerClass>();
ContainerClass _containerRef;
(...)
public long get_PKhash() { /* Return unique identifier */ }
private ItemClass( Parcel in ) {
(...)
assertTrue( (_containerRef = _parents.remove( get_PKhash() )) != null );
}
public void writeToParcel( Parcel p, int args ) {
(...)//Don't write _containerRef
_parents.put( this.get_PKhash, _containerRef );
}
}