Lecture 14: Bound Services Flashcards
Services may be ___, ___ or both depending on the circumstances
- started
- bound
Boud services define the ___ and ___ lifecycle functions, but can also define an ___ method
- onBind()
- onUnbind()
- onStartCommand()
We can think of a bound service as a form of __ relationship
client-server
The bound service represents the __, while the activities that are bound to it act like ___
- server
- clients
The purpose of a bound service is to allow a client to ___, or ___
- pass to or from the service
- call methods defined within the service
The simplest way to create a bound service is to use the ____, but this has some limitations
extend the existing Binder interface
The binder class is a form of ___ meaning it allows ___
- RPCC (Remote Procedural Call)
- one process to remotely call methods in another process
Bound services that use the Binder interface can only be bound to ___ within the same ___
- activities/services/etc
- same application
If you want to bind your service to an external activity/service you’ll need a ____
Messager
To set up a service to accept bindings you need a ___variable that contains an ___
- class
- extended instance of a Binder
onBind() returns the ___
binder object to the client for binding
The LocalBinder is an extension of Binder and implements one class: ___, which provides the ___
- getService()
- client with a local reference to the running service
When an activity is performing the bind we need to keep track of a few things.
We need a class reference to ____ and a ServiceConnection object to ___
- keep track of the service
- manage the binding on the activity side
The ServieConnection has a callback which we can use to set the ___ and change the ___
- LocalService reference
- binding status of the application
Within the Activity, a callback is created with a ___ thats used to handle the actual binding and unbinding procedure
ServiceConnection
The ServiceConnection object defines __ and __ methods which we use to set/unset the service and bound refs
- onServiceConnected
- onServiceDisconnected
Once we have a valid reference to the service, we can call __ belonging to that service directly from the reference
public methods
boundRef provides a simple Boolean check to see if the service is ___
bound and available (skipping if its not)
The code in the onServiceConnected() method is what takes the ___ from the service and calls the ___ method we defined back in the LocalBinder class
- binder
- getService()
A service created through binding will cease to exist once ___
all bound connections are closed
If you only have one activity bound to the service and it ever unbinds your service will ___
terminate and any persistent storage or data it might have contained is gone
Its possible for a service to define both ___ methods and __ methods, meaning it can be launched bound or unbound
- starting
- binding
If a service is launched as unbound and then later bound, it follows the ___ – it will not ___ when unbound
- unbound lifecycle
- automatically terminate
Fundamentally binding a service just means youre allowing other participants (activities, services,etc) to ____
call methods contained within the service