Changes

Jump to: navigation, search

Android 6 Local Bound Services – A Worked Example

15 bytes removed, 08:01, 28 January 2016
m
Text replacement - "<google>BUY_ANDROID_STUDIO6</google>" to "<htmlet>androidstudio_a6</htmlet>"
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
}
</pre>
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
Having made the changes to the class, it is worth taking a moment to recap the steps performed here. First, a new subclass of Binder (named MyLocalBinder) is declared. This class contains a single method for the sole purpose of returning a reference to the current instance of the BoundService class. A new instance of the MyLocalBinder class is created and assigned to the myBinder IBinder reference (since Binder is a subclass of IBinder there is no type mismatch in this assignment).
</manifest>
</pre>
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
The next phase is to implement the necessary code within the activity to bind to the service and call the getCurrentTime() method.
</RelativeLayout>
</pre>
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
Finally, edit the code in the LocalBoundActivity.java file to implement the showTime() method. This method simply calls the getCurrentTime() method of the service (which, thanks to the onServiceConnected() method, is now available from within the activity via the myService reference) and assigns the resulting string to the TextView:
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>

Navigation menu