I’m trying to make my objects Parcelable. However, I have custom objects and those objects have ArrayList attributes of other custom objects I have made.
What would be the best way to do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can find some examples of this here, here (code is taken here), and here.
You can create a POJO class for this, but you need to add some extra code to make it
Parcelable. Have a look at the implementation.Once you have created this class, you can easily pass objects of this class through the
Intentlike this, and recover this object in the target activity.Here, the student is the key which you would require to unparcel the data from the bundle.
This example shows only
Stringtypes. But, you can parcel any kind of data you want. Try it out.EDIT: Another example, suggested by Rukmal Dias.