我想创建一个应用程序,包含一个服务S和一个活动答:服务S是负责preprocessing,如preparing上的活性的UI显示的数据,在活动之前,一个被调用。
我希望能够从包的外部调用服务S,从另外一个Android应用程序的活动类别B说,做了preprocessing,然后当数据准备好,调用活动A.
我的问题是:
什么是共享服务S和活动?A 之间数据的最佳方式 如何与服务S中的外部b活动通信,以确定它是否已经与所有的preprocessing完成的,活性的是随时可以调用?谢谢 克里斯
解决方案什么是共享数据的最佳方式 服务S和活动?A
之间使用的本地绑定模式,并有活动绑定到服务S,然后调用该服务的公开的API来获取什么是必要的。
如何才能使外部b活动 与服务S键沟通 确定其是否已与全部竣工 它的preprocessing和活性的 是随时可以调用?
使用远程绑定模式和AIDL。 b活动将注册一个AIDL定义的回调与服务S,该服务将调用适当的时候。请参见和的这里一个例子。
I want to create an app that contains a Service S and an Activity A. The Service S is responsible for preprocessing, such as preparing the data shown on the UI of the Activity A, before the Activity A gets invoked.
I want to be able to invoke the Service S from outside the package, say from another Android app's Activity class B, do the preprocessing, and then when the data is ready, invoke Activity A.
My questions are:
What is the best way to share data between the Service S and Activity A? How can the external activity B communicate with the Service S to determine if it has completed with all its preprocessing, and the Activity A is ready to be invoked?Thanks Chris
解决方案What is the best way to share data between the Service S and Activity A?
Use the local binding pattern and have Activity A bind to Service S, then call the service's exposed API to retrieve whatever is needed.
How can the external activity B communicate with the Service S to determine if it has completed with all its preprocessing, and the Activity A is ready to be invoked?
Use the remote binding pattern and AIDL. Activity B would register an AIDL-defined callback with Service S, which the service would invoke when appropriate. See here and here for an example.
相关推荐
最新文章