0

Does writing an ArrayList to a parcel create a copy of the list when you read it back? My custom objects are Parcelable and I make sure I don't create copies. I need to be able to pass an ArrayList forward to other activities through intents and I need to be able to add and remove elements in the ArrayList in other activities.

Right now it seems like Parcel creates a copy of the ArrayList therefore I am not able to easily update the elements.

tchristofferson
  • 183
  • 1
  • 1
  • 14
  • I don't think this should be possible. If you want to have a shared element for couple of activities make it `static` or somehow outside of activities. Parceling is actually making the class instance capable of being copied. – Mahdi-Malv Sep 30 '20 at 21:01
  • No this is not possible by using parcelable. And don't make it static, use proper architecture like a ViewModel, a Repository, etc. – Nicolas Sep 30 '20 at 21:06

1 Answers1

0

Using Parcel serializes and deserializes the data. This makes copies. If you need to share the original objects then you can declare references to them as static, which can be accessed from all classes.

David Wasser
  • 93,459
  • 16
  • 209
  • 274