开发者

How does Service synchronously communicate with Activity

  1. My application contains a single main Activity and a service.
  2. 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.
  3. There would be many messages and data exchange between Activity and Service while running.
  4. 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜