Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a copy of parcel object

I am using the parcel object to pass the value from one process to another. I want to create a clone of the parcel object but I am not able to use clone() method If anyone knows how to create the copy of parcel please provide the solution.

like image 631
Brijesh Masrani Avatar asked Nov 27 '22 22:11

Brijesh Masrani


1 Answers

The suggested solution is incomplete and will not work.

Here's a working solution:

(I have an object called message of type MessageDescriptor which I want to clone)

Parcel parcel = Parcel.obtain();
message.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
MessageDescriptor messageToBeSent = MessageDescriptor.CREATOR.createFromParcel(parcel);
parcel.recycle();
like image 82
Lior Avatar answered Dec 09 '22 18:12

Lior