Reputation: 16887
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.
Upvotes: 2
Views: 1217
Reputation: 5505
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!
Upvotes: 2