Domanda

I am using 2 different fragments under one activity. One of the fragments contains a list and the other one the detailed view of each element on the list. When the activity creates the fragments, 2 object is passed as parameter on the new instance.

This is a complicated object with many fields inside (BigIntegers, ArrayLists, Strings..) This object implements Parcelable in order to be used with the fragments. When the information is passed through the fragments, there is not any problem for parsing the data, actually I think that this objects are required to be parcelable in order of saving the state, not for passing as parameters between the fragments.

This object contains inside a list of objects which contains a reference to the main one. Given O1 as Object 1 and O2 as object 2, this would be a "graphical" explanation:

O1:

  • String
  • BigInteger
  • Arraylist
  • ....
  • ArrayList

O2:

  • BigInteger
  • O1<-------- This is a reference to the O1 object

When I leave the activity (by clicking on home in the phone) and it tries to save the state, I get an StarOverflow error. Could it be related with that the parcelable enters in an infinite loop trying to save the whole object rather than the reference? I havd encountered many troubles by handlling the parcelable objects on android.

È stato utile?

Soluzione

Not quite versed in Parcelable and the way it works, but to me it seems a reference looping - i.e. the object is referenced back to itself through one or more of its properties.

See in your class definitions of Parcelables if you can loop back to any of the instances.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top