Android Parcel and Pass an object with a Listener on it
android, android-intent, parcelable
Solution
Is there any way I can pass a Parcelable (via Intent) that has a View.OnClickListener on it?
Not in any meaningful fashion. Parceling is copy-by-value, not copy-by-reference, so it is not the same object on the receiving side as on the sending side.
Basically I want to be able to start a common Actvity from anywhere and pass over the OnClickListener for a button which is defined on the Activity.
Use an event bus (Square's Otto, greenrobot's EventBus, `LocalBroadcastManager`, etc.).
Or, use a `PendingIntent`.
Or, use a `Messenger`.
Or, use a `ResultReceiver`, which is the closest thing there is to a "parcellable callback".
Problem
Is there any way I can pass a Parcelable (via Intent) that has a View.OnClickListener on it? Basically I want to be able to start a common Actvity from anywhere and pass over the OnClickListener for a button which is defined on the Activity. Alternatively I don't need to send the OnClickListener, it can just be a custom interface implementation that a fixed OnClickListener can callback to, the problem is I can't see any way to parcel anything like a callback (a method that can later be called) I had tried the following ``` destParcel.writeValue(mListener) ``` but it threw the following ``` java.lang.RuntimeException: Parcel: unable to marshal value ``` So is there anyway to write a parcellable callback?