Changes

Jump to: navigation, search

Android Local Bound Services – A Worked Example

No change in size, 15:24, 4 February 2014
Implementing the Binder
== Implementing the Binder ==
As previously outlined, local bound services can communicate with bound clients by passing an appropriately configured Binder object to the client. This is achieved by creating a Binder subclasss subclass within the bound service class and extending it by adding one or more new methods that can be called by the client. In most cases, this simply involves implementing a method that returns a reference to the bound service instance. With a reference to this instance, the client can then access data and call methods within the bound service directly.
For the purposes of this example, therefore, some changes are needed to the template BoundService class created in the preceding chapter. In the first instance, a Binder subclass needs to be declared. This class will contain a single method named getService() which will simply return a reference to the current service object instance (represented by the this keyword). With these requirements in mind, edit the BoundService.java file and modify it as follows:
<uses-sdk
android:minSdkVersion="819" android:targetSdkVersion="1719" />
<application

Navigation menu