Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 28  Background Services


Controlling Your Alarm


Now that you can turn your alarm on and off (as well as tell whether it is on or off), let’s add an
interface to turn this thing on and off. Add another menu item to menu/fragment_photo_gallery.xml.


Listing 28.11  Adding service toggle (menu/fragment_photo_gallery.xml)


<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">


<item android:id="@+id/menu_item_search"
... />


<item android:id="@+id/menu_item_clear"
... />


<item android:id="@+id/menu_item_toggle_polling"
android:title="@string/start_polling"
app:showAsAction="ifRoom" />



Now you need to add a few strings – one to start polling and one to stop polling. (You will need a
couple of other ones later, too, for a status bar notification. Go ahead and add those as well.)


Listing 28.12  Adding polling strings (res/values/strings.xml)



...
Search
Clear Search
Start polling
Stop polling
New PhotoGallery Pictures
You have new pictures in PhotoGallery.
Free download pdf