Binding to a service from an action or starting a service in different processes?

I want to establish a Bluetooth connection in the service. And there should be an interaction between Activities and Services. The service must be started as soon as the application is started, and must be able to interact with the user interface in certain situations.

What should be the appropriate way? If I bind a service to only one of the objects, then this service will exchange data only with this action. So, do I need to use an AIDL based approach or is there any other way out for this?

Otherwise, can I have a class that extends the Application class and then start the service and bind the Application class instead?

+3
source share
2 answers

This is a fairly broad question, so I will answer as best as possible. From what I know about services, several actions can connect one service, all of which have access to it. Only after all actions related to the service end with their connections (by decoupling), does the service really stop.

The Android services documentation for services tells us:

... the system will keep the service running as long as it is running or there is one or more connections to it using the Context.BIND_AUTO_CREATE flag. When none of these situations occurs, the onDestroy () method is called and the service is terminated

, , , . IBinder, . , Android :

IBinder , helpl.

, Messenger AIDL. .

, !

+1

, , Messengers. , 99,9% . (IPC). AIDL, IPC.

: BroadcastReceivers , , ( ).

0

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


All Articles