Domanda

I'm trying to send an object through an intent. From all the examples I've seen, it needs to be parcelable, and have all its sub-fields written to the parcel. Meaning that ultimately it is broken down to its ints, strings, etc. Is there a way to pass an object through an intent without all of this? Just send the object, have the receiving activity take it out of the intent, and then take whatever needed information it needs from it?

È stato utile?

Soluzione

You might be able to get away with it, just by making the object serializable, but based on the object complexion, it could cause performance issues, other than that, there's no way to send a plain object the way you want, Intent bases its objects transfer on Inter Process Communication Protocol, which requires encode objects into more primitive values and send it to another end point and then decode them.

Hope this helps.

Regards!

Altri suggerimenti

You have to implement an interface called Parelable and write your object's instances inside a parcel.

Have a look at this tutorial

http://www.codexperience.co.za/post/passing-an-object-between-activities-using-an-intent

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