How to bind two Android Activities to one Service?

前端 未结 3 1111
-上瘾入骨i
-上瘾入骨i 2021-02-06 00:21

I would like to ask for some example, where two different activities (button in first activity open second activity), are communicating with one service (AIDL, etc.) I\'ve tried

3条回答
  •  不要未来只要你来
    2021-02-06 00:54

    You can do it by using Messenger that provide IPC communication without using AIDL. This is how you can bind multiple activities to a service.

    If you need your service to communicate with remote processes, then you can use a Messenger to provide the interface for your service. This technique allows you to perform interprocess communication (IPC) without the need to use AIDL.

    Have a look at this link. When you see the code, you will find a switch case withing a Handler, this will cater to the multiple requests that you will send from you multiple activities/components. Thanks. I hope the answer will be of help to you.

提交回复
热议问题