CHAPTER 13: Android Service Class and Threads: Background Processing 485
could drop below this process priority level based upon your end-user’s usage or interaction with the
Activity subclass that contains the Thread object.
Next, you’ll learn how to write a Service subclass and how to call it using an Intent object. You will do
this using the PlayVideo.java Activity subclass that you created in Chapter 11. You will implement
the Android Service class lifecycle by creating an ambient planet audio player background Service
component named AmbientService.java. This will be a Service subclass that will extend the
Service class by utilizing the Java extends keyword inside of the class declaration to subclass the
Android Service class.
You’ll code Service class lifecycle methods in your Java code, including onCreate( ), onStart( ),
and onDestroy( ) methods. You will leverage an Android Intent object in one of these to start the
background Service, which will play background audio for the PlayVideo Activity created in Chapter 11.
Finally you will also look at how to add the
will test your background audio Service subclass inside the Nexus One emulator. Since the video
fly-over frames do not need to sync with the planet atmospheric ambient audio track, this will also
show you a unique way to optimize your video and audio assets.
Creating a Service Subclass: AmbientService
Instead of having Eclipse create your class for you, you will create a class from scratch just like you
did in Chapter 5 with your Galaxy.java class, in order to get some more practice with doing things
using that work process.
- Open your HelloUniverse project in Eclipse and right-click on your /src
folder, since that is where you want the file that you are creating to be placed. - Next, select the New ➤ Class menu sequence and open the New Java
Class dialog, shown in Figure 13-1.
Figure 13-1. The New Java Class dialog with AmbientService name and the Superclass Selection dialog