If I send a Parcelable object to another part of my program via LocalBroadcastManager -is the Parcelable immutable then? Immutable in the sense that the received Parcelable cant affect the object that was originally transmitted. I would guess so, because I guess Parcelable is a "deepcopy" serialization mechanism and not pass by reference, but I need to be sure. Can someone who knows, tell me if I have to worry about someone in the receiving end changing values on the received object, if I want to prevent that from affecting the original object...?
Asked
Active
Viewed 275 times
1 Answers
2
If I send a Parcelable object to another part of my program via LocalBroadcastManager -is the Parcelable immutable then?
That is not guaranteed. In fact, AFAIK, it does not happen at all for local broadcasts.
I guess Parcelable is a "deepcopy" serialization mechanism and not pass by reference
Only across process boundaries. That happens to include things like startActivity()
for another one of your activities, because those involve IPC. But the Intent
object -- and its extras -- is simply passed around your process with LocalBroadcastManager
. I see no place where Intent
would be forced to make a copy.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
-
But when I implement Parcelable I have this: #writeToParcel(Parcel dest, int flags) { dest.writeString(myString);} Then that must be bytified and put into Parcel dest -no? I mean does it really keep a reference back after unpack? Does it not unpack to a fresh new instance? – JohnyTex Mar 21 '14 at 15:08
-
1@user2254314: "Then that must be bytified and put into Parcel dest -no?" -- only when needed. There is nothing in `LocalBroadcastManager` that needs to convert the `Intent` into a byte array. You are welcome to review [the source code to `LocalBroadcastManager`](https://android.googlesource.com/platform/frameworks/support/+/refs/heads/master/v4/java/android/support/v4/content/LocalBroadcastManager.java). – CommonsWare Mar 21 '14 at 15:17