Reputation: 33674
I have a Location object in one of my other Venue object that implements Parcelable. How do I serialize this correctly in my writeToParcel method implementation? So here's some code:
public class Venue implements Parcelable{
public String id;
public String name;
public String address;
public Location location;
public String city;
public String state;
public String country;
public String postalCode;
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel desc, int flags) {
desc.writeString(id);
desc.writeString(state);
desc.writeString(name);
desc.writeString(address);
desc.writeString(postalCode);
desc.writeString(country);
desc.writeString(city);
//I am still missing on a way to serialize my Location object here
}
}
Upvotes: 7
Views: 4300
Reputation: 190
location = in.readParcelable(Location.class.getClassLoader());
also works.
Upvotes: 1
Reputation: 1824
Here your have a snippet how to serialize parcable objects into your own parcel.
Location location;
public void writeToParcel(Parcel desc, int flags) {
location.writeToParcel(desc, flags);
/* do your other parcel stuff here */
}
public void readFromParcel(Parcel in) {
location=Location.CREATOR.createFromParcel(in);
/* do your other parcel stuff here */
}
Upvotes: 10