- My application contains a single main Activity and a service.
- Service will run in background as long as possible even if main Activity is inactive, so I had to launch it with startService() instead of binding them together.
- There would be many messages and data exchange between Activity and Service while running.
- I'm planning to use broadIntent() to finish those communication, but you know, intents are all asynchronous. But sometimes synchronous开发者_如何转开发 communication is required.
How can I get them synchronously communicated with each other?
Thanks.
i suggest you to look for bindService and AIDL.This lets you open a communication channel between the activity and the service.
what about using LocalBroadcastManager, it will send broadcast from service to local activity only. http://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager.html
精彩评论