Android - Service and Activity interaction

后端 未结 1 1728
一生所求
一生所求 2021-02-10 07:01

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

相关标签:
1条回答
  • 2021-02-10 07:35

    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.

    0 讨论(0)
提交回复
热议问题