Search code examples
androidandroid-intentdb4o

how to combine db4o and android intents


I'm making (my first) android application and I'm a little bit puzzled with the use of db4o.

I have one activity in which I have a listView, and let the user select an object. Then I pass this object trough a series of intents to other activities (to populate its fields) and then back to the main activity.

But the problem is, when I pass an object (it is serializable), the object I get out of the intent is not the same as the one I put in. (different id, when I check with debug). All the fields are the same, but it's just not 'the same' object.

So when I try to store the updated object in the db4o, it doesn't recognize it, and stores a double.

I've figured out two workarounds:

  • Also pass an 'original/unmodified' object, and use it to get the db4o reference (through QBE), and then updating the fields of that object with the values of the changed object.

  • Using global variables so I don't have to use intents (to pass the object)

But both seem really bad to me? What could be a real solution, instead of a workaround?


Solution

  • You could try using a singleton to store your object and the fields that other classes (?) need to set so everyone has access. I'm not clear of your use of intents in this explanation.