A (175)

(Tuis.) #1

490 CHAPTER 13: Android Service Class and Threads: Background Processing



  1. The onDestroy( ) method is coded using the following Java logic, which is
    also shown in Figure 13-6:


@Override
public void onDestroy() {
ambientAudioPlayer.stop();
}

Figure 13-6. Add an onDestroy( ) method and then stop the ambientAudioPlayer MediaPlayer object playback using .stop( )


Now that you have coded your first Android Service subclass, using about two dozen lines of Java
code, you need to declare your Service subclass in your AndroidManifest file. Once you do this,
you can start it using an Intent object from your PlayVideo Activity subclass, to add background
digital audio ambient sound effects to your planet fly-over simulation.


Configuring AndroidManifest to Add a


Whenever you add an Android Activity, Service, Content Provider, or Broadcast Receiver component
to your Android application, you need to declare it for use inside of your AndroidManifest XML file,
which is utilized to define, configure, and launch your Android application.


You will do that now, by opening your AndroidManifest.xml file, inside the central editing pane of
Eclipse. At the top of the existing XML mark-up inside of the parent tag add in a child


tag before the first tag for EditGalaxy. It is important to note that the order of
the component child tags inside the parent tag does not matter, as long as they are
all in there somewhere.
Free download pdf