2

I have a situation where an activity needs to start 2 services, one is bound, one is not.

The bound will return a Ibinder to the activity. But the activity needs to some how provide a callback to both the services, i.e. both services must be able to call some methods in a nested class in the activity.

What is the best way to do this ? Should I use broadcast from services, and then call the desired API from the onReceive() ? Or can I pass a IBinder from my activity to service in the intent, and the service could use it to make a IPC call back ?

Edit

Forgot to clarify .. the two services are in a different app than the activity.

Jake
  • 16,329
  • 50
  • 126
  • 202

1 Answers1

2

you could to use LocalBroadcastManager Sending An Intent for Activity

I believe it is the best option for this scenario EventBus or Otto

EventBus is an Android optimized publish/subscribe event bus. A typical use case for Android apps is gluing Activities, Fragments, and background threads together. Conventional wiring of those elements often introduces complex and error-prone dependencies and life cycle issues. With EventBus propagating listeners through all participants (e.g. background service -> activity -> multiple fragments or helper classes) becomes deprecated. EventBus decouples event senders and receivers and thus simplifies communication between app components. Less code, better quality. And you don't need to implement a single interface!

Anderson K
  • 5,445
  • 5
  • 35
  • 50
  • What if the two services were in a different app ? (I didn't clearly state that in the question) – Jake Jul 24 '14 at 00:44
  • @Jake, Yes, it was not clear! See this http://stackoverflow.com/questions/24876319/using-intents-as-a-form-of-message-passing/24876668#24876668 – Anderson K Jul 24 '14 at 00:48