Reputation: 7152
I am using intents as a messaging mechanism of communication between various parts of my Android app.
My question is : can I subclass the Intent to build my own classes on top of it, or it will be the standard Intent class when I get it in the Broadcast reciever?
I am talking about intra process communication of course. But cross thread.
Upvotes: 4
Views: 875
Reputation: 1317
I've never done this myself, but I imagine that it's possible. Check out the LabeledIntent
documentation and source - I think this is similar to what you're describing. When handling your custom Intent
in your receiver, you'll need to cast the Intent
parameter in onReceive()
to your own subclass.
If you add any fields to your subclass, you'll need to make sure to properly implement the Parcelable
methods - make sure you override writeToParcel()
, have a constructor that accepts exactly on Parcel
parameter, and have a public static final Parcelable.Creator
object.
Upvotes: 5