How to bind two Android Activities to one Service?

前端 未结 3 1074
-上瘾入骨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:32

    This is probably old, but I'll try to answer it anyways...

    In Android, seeing as only one Activity can bind to a Service at a time, and only one Activity can be shown at a time, there is no real reason to want to bind 2 Activities at a time.

    But, if you'd like, the best solution is to bind the Service in the onResume() method, and unbind it in the onPause() method. This allows you to give two un-related Activities access to the service, while only having one bound at a time.

提交回复
热议问题