Learning Android™ Application Programming: A Hands-On Guide to Building Android Applications
by James Talbot, Justin McLean, Jorge Hernandez
Creating a Service
To create a service, you need to complete several steps. First, you create a class that extends Service. If all you need is a long-running task that runs in the background, there’s not much else you need to do. If you need to communicate with the service, you also need to override the onBind method, returning an instance of a class that implements the bindable methods. You can then communicate with that class by implementing the ServiceConnection class. Follow these steps.
1. Create a new package named services in the com.androiddevbook.onyourbike package. Use the New Class wizard to create a new class named TimerService that extends Service (see Listing 9.3).
Listing 9.3 Creating a New TimerService Class That Extends Service ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access