bind to remote service(AIDL) form handler class android -


i have remote service listens udp socket. udp send/receives happens via service. service starts on boot , last until user uninstalling service. multiple apps(client apps) can contact service in order send data via udp socket.

when message receives remote service broadcast message. client apps can catch these broadcasting messages via broadcast receiver. in order handle caught messages, client apps have handler class(plain java class). handler class needs bind remote service in order send messages back(to service).

all these communications happens in background(with out interacting ui)

so how bind handler class remote service. can use service connection plain java class?

you can bind service pojo (plain old java object). need access context in order pojo call bindservice(). can have client app pass context parameter constructor of pojo, or parameter of other method of pojo.

your pojo need provide serviceconnection in call bindservice(). serviceconnection object callbacks when service connected , disconnected. pojo need keep track of whether has active connection service, can bind service when needed.

be aware call bindservice() asynchronous. means need wait callback serviceconnection.onserviceconnected() before can call methods on bound service. call onserviceconnected() executed on main (ui) thread. may have implications on architecture of application.


Comments