Android Programming The Big Nerd Ranch Guide, 3rd Edition
537 28. Background Services All the code you have written so far has been hooked up to an activity, which means that it is assoc ...
Chapter 28 Background Services 538 A service’s intents are called commands. Each command is an instruction to the service to do ...
Creating an IntentService 539 Because services, like activities, respond to intents, they must also be declared in your AndroidM ...
Chapter 28 Background Services 540 What Services Are For OK, we admit it: Looking at those Logcat statements was boring. But th ...
Safe background networking 541 Listing 28.4 Checking for background network availability (PollService.java) public class PollSe ...
Chapter 28 Background Services 542 Looking for New Results Your service will be polling for new results, so it will need to kno ...
Looking for New Results 543 Return to PollService.java and put this plan into action. Listing 28.7 shows a long swath of code, b ...
Chapter 28 Background Services 544 Delayed Execution with AlarmManager To actually use your service in the background, you will ...
Being a good citizen: using alarms the right way 545 After that, you need to either set the alarm or cancel it. To set the alarm ...
Chapter 28 Background Services 546 Repeating alarms: not so exact The setRepeating(...) method sets a repeating alarm, but that ...
PendingIntent 547 PendingIntent Let’s talk a little bit more about PendingIntent. A PendingIntent is a token object. When you ge ...
Chapter 28 Background Services 548 Controlling Your Alarm Now that you can turn your alarm on and off (as well as tell whether ...
Controlling Your Alarm 549 Now delete your old debug code for starting the alarm and add an implementation for the menu item. Li ...
Chapter 28 Background Services 550 In onCreateOptionsMenu(...), check whether the alarm is on and change the text of menu_item_ ...
Notifications 551 Notifications Your service is now running and doing its thing in the background. But the user never knows a th ...
Chapter 28 Background Services 552 Make PollService notify the user that a new result is ready by creating a Notification and c ...
Challenge: Notifications on Android Wear 553 notification. It should be unique across your application. If you post a second not ...
Chapter 28 Background Services 554 Let’s see what lifecycle callbacks a service has. A service’s lifecycle For a service starte ...
Bound services 555 Once a sticky service is started, it is “on” until a component calls Context.stopService(Intent). If the serv ...
Chapter 28 Background Services 556 private class MyBinder extends IBinder { public MyService getService() { return MyService.th ...
«
24
25
26
27
28
29
30
31
32
33
»
Free download pdf