0

Is parcelable data persistent? I have some variables that I destroy in android lifecycle functions such as onDestroy() , but what about things written to parcelable?

Ultimately I would want to pass elements of my parcelable objects via intents, will they still be available after garbage collection (either java or dalvik's)?

thank you

CQM
  • 42,592
  • 75
  • 224
  • 366

1 Answers1

2

The short answer is: yes. Parcelable data is persistent.

When you make a Parcel out of an object, you are basically creating a serialized version of the at object. Once you have the serialized version, the object itself can be garbage-collected and you will still have the Parcel (assuming that you have kept a handle on that, or if you have sent it via Intent then the OS has a handle on it).

At another time you can instantiate a new object from the Parcel and you will end up with a copy of the original object, regardless of whether the original object has been garbage-collected or not.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • how do I retrieve a parcel if I didn't pass it to the current activity? this is how I would get it if I did pass it, `Bundle b = getIntent().getExtras(); ObjectA obj = b.getParcelable("com.package.ObjectA");` but if I didn't ? – CQM May 14 '12 at 15:44
  • Not sure I understand your question. When you create a Parcel, it is just a String. You could store it in a static (class) member variable or send it via IPC to another process or something else. Maybe you need to explain in more detail what it is you are trying to do. – David Wasser May 14 '12 at 16:00
  • I just don't completely understand the concept of parcels and how it contains my data object. – CQM May 14 '12 at 16:05
  • Not sure I can explain the concept of Parcel in 500 characters ;-) Have you read the developer documentation on Parcel? As I said, a Parcel is a serialized object (ie: all the data of an object written to a byte stream in a known sequence and format). It is the responsibility of each class that implements the Parcelable interface to provide methods that can turn an instance of the class into a Parcel and vice-versa. If you are familiar with Java's `Serializable` interface, this is a similar concept. – David Wasser May 14 '12 at 16:19