Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is one complete example: <a href="http://android-in-practice.googlecode.com/svn/trunk/ch02/DealDroidWithService/" rel="nofollow noreferrer">http://android-in-practice.googlecode.com/svn/trunk/ch02/DealDroidWithService/</a></p> <p>The pattern this example uses, and one that I've found that seems to work well, is to use a boot receiver to setup the <em>AlarmManager</em> (and of course also check to start the polling from your main <em>Activity</em> too, for the case when your app is installed and the system is not booted) and have the <em>AlarmManager</em> send an <em>Intent</em> for another receiver: <a href="http://android-in-practice.googlecode.com/svn/trunk/ch02/DealDroidWithService/src/com/manning/aip/dealdroid/DealBootReceiver.java" rel="nofollow noreferrer">http://android-in-practice.googlecode.com/svn/trunk/ch02/DealDroidWithService/src/com/manning/aip/dealdroid/DealBootReceiver.java</a></p> <p>And then from the <em>AlarmReceiver</em> start an <em>IntentService</em>: <a href="http://android-in-practice.googlecode.com/svn/trunk/ch02/DealDroidWithService/src/com/manning/aip/dealdroid/DealAlarmReceiver.java" rel="nofollow noreferrer">http://android-in-practice.googlecode.com/svn/trunk/ch02/DealDroidWithService/src/com/manning/aip/dealdroid/DealAlarmReceiver.java</a></p> <p>From your <em>IntentService</em> then make your network call to poll for data, or whatever you need to do. <em>IntentService</em> automatically puts your work in a background thread, it's very handy: <a href="http://android-in-practice.googlecode.com/svn/trunk/ch02/DealDroidWithService/src/com/manning/aip/dealdroid/DealService.java" rel="nofollow noreferrer">http://android-in-practice.googlecode.com/svn/trunk/ch02/DealDroidWithService/src/com/manning/aip/dealdroid/DealService.java</a></p> <p>Check the docs for these classes too, a lot of into in there. </p> <p>The caveat with this example is that it does <em>not</em> deal with the wake lock gap (the excellent CommonsWare code does that if you need it), but it may give you some more ideas about how to potentially address the "poll using AlarmManager and Service" stuff.</p> <p>UPDATE: the code is now here: <a href="https://github.com/charlieCollins/android-in-practice" rel="nofollow noreferrer">https://github.com/charlieCollins/android-in-practice</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload