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 29.11  Add service toggle (menu/fragment_photo_gallery.xml)

<​m​e​n​u​ ​x​m​l​n​s​:​a​n​d​r​o​i​d​=​"​h​t​t​p​:​/​/​s​c​h​e​m​a​s​.​a​n​d​r​o​i​d​.​c​o​m​/​a​p​k​/​r​e​s​/​a​n​d​r​o​i​d​"​>​ ​ ​<​i​t​e​m​ ​a​n​d​r​o​i​d​:​i​d​=​"​@​+​i​d​/​m​e​n​u​_​i​t​e​m​_​s​e​a​r​c​h​"​ ​ ​ ​ ​a​n​d​r​o​i​d​:​t​i​t​l​e​=​"​@​s​t​r​i​n​g​/​s​e​a​r​c​h​"​ ​ ​ ​ ​a​n​d​r​o​i​d​:​i​c​o​n​=​"​@​a​n​d​r​o​i​d​:​d​r​a​w​a​b​l​e​/​i​c​_​m​e​n​u​_​s​e​a​r​c​h​"​ ​ ​ ​ ​a​n​d​r​o​i​d​:​s​h​o​w​A​s​A​c​t​i​o​n​=​"​i​f​R​o​o​m​"​ ​ ​ ​ ​a​n​d​r​o​i​d​:​a​c​t​i​o​n​V​i​e​w​C​l​a​s​s​=​"​a​n​d​r​o​i​d​.​w​i​d​g​e​t​.​S​e​a​r​c​h​V​i​e​w​"​ ...

Get Android Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.