
- HOW TO RETURN AN OBJECT FROM AN INTENT ANDROID STUDIO ANDROID
- HOW TO RETURN AN OBJECT FROM AN INTENT ANDROID STUDIO CODE
Actual object serialization do in writeToParcel method. There are two methods to override from Parcelable interface describeContents and writeToParcel. This is a simple object which keeps user related data. Then object capable to put in to an intent with intent.putExtra methodįollowing is an example implementation of parcelable object( User) When need to pass custom object between activities we can mark the object as Parcelable(Implement the Parcelable interface).
HOW TO RETURN AN OBJECT FROM AN INTENT ANDROID STUDIO ANDROID
It is highly recommended to use Parcelable implantation when serializing objects in android The performance of Parcelable is very high when comparing to Serializable because of its custom implementation param intent An Intent, which can return result data to the caller (various data can be attached to Intent extras). So it creates less garbage objects in comparison to Serialization

HOW TO RETURN AN OBJECT FROM AN INTENT ANDROID STUDIO CODE
In Parcelable, developers write custom code for marshaling and unmarshaling. Parcelable is android own serialization protocol. So when object implements Serializable Java will automatically serialize it. Serializable is a marker interface, which implies the user cannot marshal the data according to their requirements. 3.Use putExtra(String name, Parcelable value) to add it to the intent in ActivityA. Parcelable (Implement object as Parcelable).Serializable (Implment object as Serializable).In android there are two ways to achieve marshaling and unmarshaling of java objects.Converting it back to its live, in-memory representation is called deserializing or unmarshaling. Serialization is converting data from a fast, efficient, internal representation to something that can be kept in a persistent store or transmitted over a network.Ĭonverting data to its serialized form is often called marshaling it. create an instance of the Intent object to return data. This is the place where serialization comes. From the second activity, pass the data to the Main activity by using setData () method, as I have already discussed in my previous article. We can just put the them to intent with unique key and send it to an another activity.īut it is bit complex when passing custom objects between activities. Passing simple data types (String, int, double,…ect) between activities is easy.
