Alarms

Your application may for some reason need to wake up every now and then to perform some operation. A typical example would be an RSS reader application that wakes up every 30 minutes to download RSS feeds so that the user always has an updated view of the feed when the application is started, or a stalker application that sends a message to one of your contacts every 5 minutes. Listing 7–16 shows how an alarm can be created to wake up the application and start a service that simply prints out a message and terminates. Listing 7–17 shows the implementation of the service.

Listing 7–16. Setting Up An Alarm

    private void setupAlarm(boolean cancel) {         AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);         Intent ...

Get Pro Android Apps Performance Optimization 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.