If you want to pass an object via Bundle you have to serialize it or to implement the Parcelable interface (it is an Android Implementation for Java serializable). It is recommended the second option because it is faster than the first one.
Steps to implement Parcable:
- … implements Parcelable
2. Implement the two methods, describeContents() and writeToParcel()
If you write an other parcelable you should do it this way:
3. All the classes implementing the Parcelable interface must also have a static field called CREATOR that implements the Parcelable.Creator interface.
4. Now implement the methods createFromParcel() and newArray():
You should have a private constructor in your class that read the values from the Parcel in the same order your wrote them in the Parcel.
If you read an other parcelable you should do it this way:
parcelableName = source.readParcelable(ClassName.class.getClassLoader();
- Android – Notifications
- Content Provider – Part 3 – insert, delete, update, getType
- Content Provider – Part 2 – create and query