A (175)

(Tuis.) #1
CHAPTER 13: Android Service Class and Threads: Background Processing 491

Your tag should implement the android:enabled=“true” parameter. This parameter
will enable your Service component for use inside of your application. Be sure to also include the
android:name=“.AmbientService” parameter, which is used to reference the MusicService.java
class name. You will be creating this Service class in the next section of the chapter. The tag
mark-up should look like this:



The finished AndroidManifest.xml file and mark-up is shown in Figure 13-7.


Figure 13-7. Open the AndroidManifest.xml file and add a child tag under the parent tag


Next, you will create the turn audio on and turn audio off icon UI elements. This UI design will overlay
these icons over the digital video player surface, so that the user can click on these floating icons.
These icons will use alpha channel transparency as well as allow users to click (or touch) them to turn
on (start the Service) and off (stop the Service) the ambient planet background audio sound effects.


Starting a Service: Using .startService( )


Now that you have created your AmbientService Service subclass and declared it for use in your
AndroidManifest XML file, you are ready to start it using the .startService( ) method that you
learned about earlier in the chapter. This is done using an Intent object in a very similar fashion to
starting an Activity, which you have done already, so this should be familiar to you.


After you copy the sound0.png and sound1.png audio off and audio on icon graphics from the
book repository into your /HelloUniverse/res/drawable-hdpi folder, as can be seen in Figure 13-8,
you will begin working on adding to the user interface infrastructure that is currently in your

Free download pdf