1. Binding to services from activities
If the
activity
wants to
interact with the
service directly,
it can use
the
bindService()
method to start the
service.
This method requires a
ServiceConnection
object as a parameter which is called on the service start and when finishing its
onBind()
method. This method
returns a
IBinder
object to the
ServiceConnection
.This
IBinder
object
can be used
by the
activity
to communicate
with the
service.When the binding process has finished, the
onStartCommand()
method in the service is called with the
Intent
object used for the
bindService()
method.2. Local services bindings
If the service runs in the same process as the activity, it is
possible to return the service to the activity. This allows that the
activity can call methods of the service directly. This technique is
demonstrated by <xref linkend="exercise_bindlocalservice" />.
3. Interprocess communication services bindings
If the service run in its own process, you require IPC
(Interprocess
Communication) to communicate with the service.
No comments:
Post a Comment