How To Use The Parcelable Class Properly In Android
I have a class (below) that I want to send to a Service Class through an Intent. I have implemented the Parcelable interface but am unsure how to actually send and retrieve the en
Solution 1:
In your writeToParcel function, you need to write which state objects you want to the Parcel, for instance:
@OverridepublicvoidwriteToParcel(Parcel dest, int flags) {
dest.writeString(urlPath);
dest.writeString(hostname);
}
It doesn't matter which order you write the objects, so long as you read them back in in the same order:
@OverridepublicUrlParamsHelper(Parcel in) {
urlPath = in.readString();
hostname = in.readString();
}
The problem is that you can only read and write the object types mentioned in the documentation for Parcel, so it may be difficult to save absolutely everything.
Post a Comment for "How To Use The Parcelable Class Properly In Android"