Martin Dobrev
Martin Dobrev

Reputation: 3

Extending Intent class in Android?

I am trying to extend the "android.content.Intent" class by adding a private attribute of a custom class. My goal is to send complex objects from the main Activity to a background Service. The extension itself is not a problem, the class gets compiled without any errors and the project runs. The only problem is that the BroadcastReceiver does not receive the modified Intent and the "onReceive" method gets never called. It there any way to pass complex objects with the help of Intents?

Thanks in advance, Martin

Upvotes: 0

Views: 2164

Answers (1)

Vincent Mimoun-Prat
Vincent Mimoun-Prat

Reputation: 28551

Your objects need to implement the Parcelable interface. Then you can pass them in your intents using Intent#putExtra(String, Parcelable) and retrieve them using (MyObject) Intent#getParcelableExtra(String).

Upvotes: 2

Related Questions