Search code examples
javaandroidandroid-intentserializable

Pass serialzable object or query database again?


I have a FoodObject instantiated on MainActivity. I'd like to show EditActivity, where FoodObject populates the appropriate fields on the EditActivity and is ready to be edited.

I see two options: (1) Pass EditActivity the _id of the FoodObject and have it query the db to get the FoodObject using Loader, etc. - OR - (2) Pass EditActivity the FoodObject directly as a serializable using intent.putExtra().

I'm very new to Android/Java (many years of obj-c, though), so I'm not sure what is best practice.

Any feedback is appreciated.


Solution

  • Best practice would be to pass in the ID of the object and then re-query it in EditActivity. You should also stay away from Serializable whenever possible as it does not perform very well (see http://www.developerphil.com/parcelable-vs-serializable/).