question

kiran-igo avatar image
kiran-igo asked

Reason for ADMMessageReceiver::onReceive being marked final

Is there a reason why ADMMessageReceiver::onReceive is marked final? I need a custom broadcast receiver to handle other services(eg. in-app purchasing).
amazon device messaging
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

adm-support avatar image
adm-support answered
Hi kiran_igo, The receiver is marked final because the logic that redirects a message from the receiver to the message handler is in there, and isn't expected to be modified. We recommend creating a separate broadcast receiver to handle other services.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

kiran-igo avatar image
kiran-igo answered
It just seems pointless to have the class marked abstract, and the onReceive method marked final when there's nothing to be overridden other than the default constructor. Easiest thing to do in my custom receiver would be to instantiate the ADMMessageReceiver with the appropriate constructor and call onReceive().
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

adm-support avatar image
adm-support answered
Hi kiran_igo, I'm not clear exactly what you are trying to do but here are the design decisions behind this class structure. You can create as many receivers as you wish so there is no need to combine all functionality in one receiver. We designed ADM to stand apart from all other SDK functionality and we intend for client code to create a receiver just for ADM. About ADMMessageReceiver usage and design: 1. Client code should never try to create instances of ADMMessageReceiver or try to register it as broadcast receiver in manifest. 2. Client code should create a class derived from ADMMessageReceiver and register it in manifest to allow ADM to receive required intents. 3. Client code should never use ADMMessageReceiver or derived classes for any other purposes and should never call onReceive method. Here is the example from our documentation ( https://developer.amazon.com/sdk/adm/integrating-app.html): public class MyADMMessageHandler extends ADMMessageHandlerBase { public static class Receiver extends ADMMessageReceiver { public Receiver() { super(MyADMMessageHandler.class); } // Nothing else is required here; your broadcast receiver automatically // forwards intents to your service for processing. }
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

kiran-igo avatar image
kiran-igo answered
Thanks for clearing that up. Till earlier today, I was under the impression you could only have one receiver declared in the manifest. I'm still not convinced of the need for multiple receivers, however. Kiran
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.