Why use the Android Bound Service?

I am curious to know why you are using the Bound Service for two-way interaction between Activity and Service, when you can perform the same interaction with the Started Service using local broadcasts and receivers defined both in Activity and in the service

It will be useful to know the pros and cons of each implementation.

I could not find any clear answer to this.

+4
source share
2 answers

Border use is Servicemuch more flexible. You can define methods on Service(using AIDL) that return immediate results (synchronously) that you cannot do using LocalBroadcastManager. Usage LocalBroadcastManagerrequires you to use it in a Servicecompletely asynchronous way. This will cancel the initiation of the service's action with the return of results (callback), which can make your code more complex and difficult to understand. Asynchronous use has some advantages, and there are places where you should use it, but if you have one Service, you can choose when to use synchronous calls and when to use asynchronous callbacks.

, AIDL . startService(Intent), , Intent, , " " / .

@CommonsWare , LocalBroadcastManager , Service , ( , , ).

+2

- , . . , , , . :

: , , , . , , , , startService(). , Splash.

: -, , , (IPC). , , bindService().

0

Source: https://habr.com/ru/post/1677044/


All Articles